Fascinating! This story made me chuckle until I thought about it a bit. Then my head started spinning as I thought of all the paradoxes time travel creates..
No, not really, I was just eating my lunch and thinking about nothing in particular.
Author Archives: Donncha
Shrub and War Links
Welcome to the White House – enjoy your visit.
Point-Counterpoint: The War On Iraq
“To take over a country and impose one’s own system of government without regard for the people of that country is the very antithesis of democracy”?
You are completely wrong.
Trust me, it’s all going to work out perfect. Nothing bad is going to happen. It’s all under control.
Dublin Bus – How To Use The Bus
Using Smarty to implement the MVC design pattern in PHP
Here’s my first go trying to create a registration page using the Model View Controller design.
Before you delve into the code, here’s some background not included in the code:
- You’ll need to know something about Smarty before reading this. Their crash course is useful for this.
- Here’s a Google Search to find more MVC information and tutorials.
- My template dir is “./templates” and for every template file I also have a php file which defines information used by the template. In my example, that includes a list of fields for the registration page. (so I use a Smarty foreach loop to create the form)
- I only have one model and view despite the fact a registration page could be two pages: initial registration page, and a thank you page. The one “view” class displays both by using different Smarty templates.
- I haven’t included the HTML templates as they’re not as interesting as the code.
- In Java land they tend to use page redirects to load alternate pages (ie. send a “Location” HTTP header or use meta tags) but I’ve hijacked the view controller by redefining the view template so it points at “thankyou.tpl” instead of “registration.tpl”. See the switch statement in RegistrationController::main()
I posted some more information to the webdev mailing list too.
I’d appreciate any comments and feedback!
<?php
require_once( “Smarty.class.php” );class registrationView
{
var $smarty;
var $model;function registrationView( &$model, $template )
{
$this->smarty = new Smarty;
$this->model =& $model;
$this->setTemplate( $template );
}function setTemplate( $formTplName = ‘registration’ )
{
$this->formTplName = $formTplName . “.tpl”;
if( is_file( “templates/” . $formTplName . “.php” ) )
{
include_once( “templates/” . $formTplName . “.php” );
$this->fields = $fields;
}
else
{
$this->fields = array();
}}
function display()
{
$this->smarty->assign( “fields”, $this->fields );
$this->smarty->assign( “form”, $this->model->getFormValues() );
$this->smarty->assign( “error”, $this->model->getErrorValues() );
$this->smarty->display( $this->formTplName );
}}
class registrationModel
{
var $form;
var $db;function registrationModel( &$form )
{
$this->db = new DB_Tsc;
$this->form = $form;
}function getFormValues()
{
return $this->form;
}function getErrorValues()
{
return $this->error;
}function validateForm()
{
$ret = true;
if( is_array( $this->form ) )
{
reset( $this->form );
foreach( $this->form as $key => $val )
{
if( $val == ” )
{
$this->error[ $key ] = true;
$ret = false;
}
}
}
else
{
$this->error[ ‘warning’ ] = “Please complete the form”;
$ret = false;
}
return $ret;
}function saveForm()
{
}
}class RegistrationController
{
var $view;
var $model;
var $page;function RegistrationController( $page, &$form )
{
$this->page = $page;
$this->model = new registrationModel( $form );
$this->view = new registrationView( $this->model, “registration” );
}function main()
{
switch( $this->page )
{
case “validate”:
if( $this->model->validateForm() )
{
$this->model->saveForm();
$this->view->setTemplate( ‘thankyou’ );
}
$this->view->display();
break;
default:
$this->view->display();
break;
}
}
}$t = new RegistrationController( $page, $form );
$t->main();
?>
The Hours
I went to see The Hours last night with Martina. She loved it but I thought it was the worst pile of cack ever. I couldn’t wait for it to finish, nodded off once or twice and I heard snoring a few rows ahead of us.
Lots of people love this film, the BBC described it as a brilliantly conceived observation of life. “The Hours” is one for the ages. but warned “The Hours” is a purely intellectual exercise, with Daldry never quite bridging the emotional gap that would have elevated this from excellence to greatness.
More reviews via Google
www.logemann.info – why to use template-engines
I was looking at this yesterday with the view to using MVC and Smarty for an app. This introductory tutorial has disappeared in 404 land so grab it quick from the Google Cache while it’s there still.
A Page For Ireland
Do you want an alternative view of Ireland? hehe. (via doc on IRC)
Cork – the second City or the ‘real’ capital if you listen to any unbiased Cork person. Cork people are known for their genorosity, in fact copper wire was invented in Cork by two men fighting over a penny.
Paradise…
It’s nice outside, but the view out my office window doesn’t look anything like paradise.
AmphetaFrames templates for AmphetaDesk
James Eaton mailed me a while back with this Amphetadesk mod, but I forgot to blog it at the time. It’s a decent mod of this rss news aggregator that adds frames to the reader interface. I have to confess I prefer Ampheta Outlines as I don’t have to click around to read the rss summaries and news. Usually when I get around to reading news, it’s while Xwrits is on and I want to relax for 5 minutes to give my hands a break from keyboard and mouse use.
A thread on ILUG reminded me to post all this for your convenience 🙂
I'm selling my car.. *sob*
I’m selling my car, it’s a sad day but my Alfa Romeo 147 is going on to another owner later on today. The 147 was the first car I really loved to drive. It’s solid on the road, very responsive 1.6lt engine, lots of features and very comfortable to drive.
The cost of living in Ireland has gone crazy in the last year. The cost of motor insurance has always been a problem for the Irish driver, and the Government squeezes more out of the Irish motorist than most other sectors of the economy through taxes.
She’s a beautiful car, and a joy to drive. If you’re thinking of buying, let me heartily recommend them.
