hmz 4dev hmz 4dev -3 years ago 93
PHP Question

How to call init() method of a controller by default in all actions



class IndexController extend AbstractActionController
{
construct__()
{
$view = new ViewModel();
}

public function init()
{
$exp = 'exemple';
$this->view->setVariable('exp', $exp);
}

public function indexAction()
{
// I Want call init in all action without $this->init();
}

public function aboutAction()
{
// I Want call init in all action without $this->init();
}
}


I want call function
init()
by default on all actions of this controller without manually typing
$this->init()

Answer Source

// I find solution in my question 
//thanks for all peopole that they help me 

class indexController extends AbstractController{

public function __construct()
{
$this->init();
}

protected function init()
{
$view = new ViewModel();
$view->setVariaa*ble($tt,'message')

return $view;
}

public function indexAction()
{
return $view;
}

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download