Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-18-2008, 10:02 PM
Junior Member
 
Join Date: May 2008
Posts: 2
Default Changing default view->render() path?

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!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 05-19-2008, 08:49 PM
Junior Member
 
Join Date: May 2008
Posts: 2
Default

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');
	}

}
And this now renders ../application/module/views/scripts/role-action.phtml.

I'm not sure how this will work in practice, but at least I have the option now!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 11:22 PM.