Login +

Reference Guide / SLS_GenericController

SLS_GenericController1 is the parent class of every Controller, it contains methods for loading generic Model, the information of the current page, and routing interfaces of the application.

Accessibility

At Controller level, youaccess it directlyby thekeyword $this:

$this->method();

Model loading

To load and use a Model of your choice, simply use the useModel() function:

$this->useModel($model,[$db];

Parameter $model must contain the name of the Model to use, $db the alias of the database on which is located the table. If it is omitted, the default database will be used.

Metas

To dynamically change the metas of the current action, you can use a number of functions setMeta…($value, $incremental=false):

$this->setMetaAuthor($author);
$this->setMetaCopyright($copyright);
$this->setMetaDescription($description);
$this->setMetaKeywords($keyword1.",".$keyword2);
$this->setMetaRobots($robots);
$this->setMetaTitle($title);

You can concatenate the existing meta (set during the creation of the action), with a new value:

$this->setMetaTitle($titleMore, true);

URL

- To redirect to a Controller / Action site, you can use the forward() function:

$this->forward($controller, $action, $params=array(), $lang="");

$params is a multiple array allowing you to spend many additional parameters to the application as necessary:

$params = array(array("key" => $key, "value" => $value));

- To redirect to a free url, you can use the redirect() function:

$this->redirect("http://www.sillysmart.org");

- To dispatch the application on a Controller / Action without reloading the page or change the url, use the dispatch() function:

$this->dispatch($controller, $action, $params=array());

Related :

References

  1. SLS_GenericController - Controller Generic - Father's controller of each Actions Controllers