|
|||
|
Hey,
i was wondering if there was a way to alter the automatic view rendering path. Instead of writing .phtml files for each controller, I want to write them for each role and controller. For example, guestindex.phtml would be rendered by the index Controller when the role of the user is a guest, and adminindex.phtml is rendered after an admin goes to the index Controller. I have seen ways to change the path to scripts, but I don't think that will help in my situation. I'm thinking along the lines of intercepting the controller before it renders and changing the path to '/'.$controller'./.$role.$controller;, but I'm not sure how to do this (I would probably be able to do it in the front controller by writing a plugin, but I'm not if I can write those for other Controllers). I hope I've explained myself well enough! |
|
|||
|
I've found a way to do this, so I may as well post it in case anyone else wants to know
![]() I did end up creating another plugin, taking the auth and viewRenderer instances as arguments. Here's the plugin code: Code:
class adam_Plugin_RolePath extends Zend_Controller_Plugin_Abstract {
private $_auth;
private $_viewRenderer;
public function __construct($auth, $viewRenderer){
$this->_auth = $auth;
$this->_viewRenderer = $viewRenderer;
}
public function preDispatch(Zend_Controller_Request_Abstract $request){
if ($this->_auth->hasIdentity()) {
$role = $this->_auth->getIdentity()->role;
}
else {
$role = 'guest';
}
$this->_viewRenderer->setViewScriptPathSpec(':controller/'.$role.'-:action.:suffix');
}
}
I'm not sure how this will work in practice, but at least I have the option now! |
![]() |
| Thread Tools | |
| Display Modes | |
|
|