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.
2
Answers
Yes, thats what
Controller
is meant for.To avoid using
$_SESSION
that seems to be a bit overkill for this particular case you can setseoController
attributes, for example,And access them from the caller
You would normally have things like meta tags stored with the model it’s describing. So if you’re loading say, a product from a model, then that model may also return the meta tags for that product:
Your controller action would then return the data needed to be displayed in a view, which could be a HTML template, JSON, XML etc.