class Base_Admin extends \Base_Controller { public function before() { parent::before(); $this->template->mainmenu = \Presenter::forge('mainmenu'); } }
...
namespace Admin;
class Controller_Admin extends Base_Admin { public function before() { parent::before(); $this->template->mainmenu->set('active', 2); }
public function action_index() { $this->template->set('content', 'helo world'); } }
and that Presenter:
namespace Admin;
class Presenter_Mainmenu extends \Presenter { public function before() { parent::before();
I want to have default value of active property = 0 and I want to have ability to change this as I do it in Controller_Admin:
$this->template->mainmenu->set('active', 2);
But what I have? If I set default value then I can't change it anyway! If I don't set default value and not set it in Controller_Admin then I have an error 'Undefined variable: active'. What is wrong in my dicision?
Fuel uses a model of late rendering for both views and presenters, which means the object is only rendered when it has to be.
This also means that your Presenter's before is only called when the object is rendered, which is long after your controller code is finished. The $this->active = 0; will therefore overwrite any value you may have set before.