lundi 20 avril 2015

Setting local variables cleanly in a MVC pattern in PHP

I am experimenting with using the MVC pattern to set local vars in some code ie

$action=basename(__FILE__, '.php');               // load action from filename for consistancy (index for this case)
$controller = new seoController($action . '-seo'); // register controller with page action and parameter
$controller->invoke();                            // invoke controller for processing

$page_title = "<insert page title here>";
$page_desc = "<insert page desc here>";
$page_keys = "<insert page keywords here>";

Of course the controller calls the model and does all the backend stuff parsing the input, getting the data and then returning.

What I would like is a clean way to set the local $page_title etc vars from the seoModel that is instantiated in setController without using the $_SESSION or any other hacky kind of way.

Is it ok from a design POV to put methods in the controller to get the info? ie

$page_title = seoController->getPageTitle();

My controllers as of now are not being used in this type of way as all they do is connect my models to the views.

I hope I'm being clear enough with my explanation.

Aucun commentaire:

Enregistrer un commentaire