in Zend Framework, whats the best way or recommended way to show or hide parts of a page depending on some criteria (technically just a variable)?
eg.
- variable passed by controller
- logged in user
- acl
in Zend Framework, whats the best way or recommended way to show or hide parts of a page depending on some criteria (technically just a variable)?
eg.
Thats how i do it
Loginform:
if (!Zend_Auth::getInstance()->hasIdentity()) {
// show login form
} else {
// show "logged in as smoove666"
}
Everything else:
// in Controller
$this->view->showSomething = false;
// in view
if ($this->showSomething) {
// whatever
}
If your logic depends on users ACL, then you just need to do like this article and this.
For other types, you can just control it inside your controller, then pass the flag to your view and do an if conditional to show your content.
And if you need something more advanced you can create your own class that deal with this logic. You can take as example the ACL class of Zend Framework.
To make your life ease, you can use view helpers. You can create your own or use partials for example.
Also, take a look at this article