RE: [fw-general] interaction between controller plugin and front controller or view
As far as I know, a plugin is not View aware. You can that functionality by: $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer'); So your plugin could be like this: class AuthPlugin extends Zend_Controller_Plugin_Abstract { public function preDispatch(Zend_Controller_Request_Abstract $request) { $auth = Zend_Auth::getInstance(); if ($auth-hasIdentity()) { $viewRenderer-view-user = $auth-getIdentity(); } } } Cheers, Holger -Original Message- From: Denis Fohl [mailto:[EMAIL PROTECTED] Sent: Tuesday, April 15, 2008 5:21 PM To: fw-general@lists.zend.com Subject: [fw-general] interaction between controller plugin and front controller or view Hi all, i'm learning with zend framework and mvc architecture... and it's hard for me :-) Beause i want it for each controller in my app i made a plugin wich purpose is to test if user is authenticated. I would like it, if true, to pass the info to the view but it does not work, even i user is authenticated, my view var is null. I suppose it's because the view objetc is not yet initialised when the plugin is executed but i can't see where or when to do this. Here is my plugin : class AuthPlugin extends Zend_Controller_Plugin_Abstract { public function preDispatch(Zend_Controller_Request_Abstract $request) { $auth = Zend_Auth::getInstance(); if ($auth-hasIdentity()) { $this-view-user = $auth-getIdentity(); } } } thanks for help -- Denis
RE: [fw-general] interaction between controller plugin and front controller or view
Sorry forgot to put $viewRenderer into the preDispatch function. === As far as I know, a plugin is not View aware. You can that functionality by: $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer'); So your plugin could be like this: class AuthPlugin extends Zend_Controller_Plugin_Abstract { public function preDispatch(Zend_Controller_Request_Abstract $request) { $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer'); $auth = Zend_Auth::getInstance(); if ($auth-hasIdentity()) { $viewRenderer-view-user = $auth-getIdentity(); } } } Cheers, Holger -Original Message- From: Denis Fohl [mailto:[EMAIL PROTECTED] Sent: Tuesday, April 15, 2008 5:21 PM To: fw-general@lists.zend.com Subject: [fw-general] interaction between controller plugin and front controller or view Hi all, i'm learning with zend framework and mvc architecture... and it's hard for me :-) Beause i want it for each controller in my app i made a plugin wich purpose is to test if user is authenticated. I would like it, if true, to pass the info to the view but it does not work, even i user is authenticated, my view var is null. I suppose it's because the view objetc is not yet initialised when the plugin is executed but i can't see where or when to do this. Here is my plugin : class AuthPlugin extends Zend_Controller_Plugin_Abstract { public function preDispatch(Zend_Controller_Request_Abstract $request) { $auth = Zend_Auth::getInstance(); if ($auth-hasIdentity()) { $this-view-user = $auth-getIdentity(); } } } thanks for help -- Denis
Re: [fw-general] interaction between controller plugin and front controller or view
now it works, it is possible to set the view object in the plugin. Your post and some posts by Matthew help me to try this : class AuthPlugin extends Zend_Controller_Plugin_Abstract { public function preDispatch(Zend_Controller_Request_Abstract $request){ $view = new Zend_View(); $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer'); $viewRenderer-setView($view); $auth = Zend_Auth::getInstance(); if ($auth-hasIdentity()) { $view-user = $auth-getIdentity(); } } } I have now my user authentification set automatically in all my controllers and views... that's what i wanted for the moment, even if its not the state of the art regarding MVC architecture. Thank you. Holger Lampe a écrit : As far as I know, a plugin is not View aware. You can that functionality by: $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer'); So your plugin could be like this: class AuthPlugin extends Zend_Controller_Plugin_Abstract { public function preDispatch(Zend_Controller_Request_Abstract $request) { $auth = Zend_Auth::getInstance(); if ($auth-hasIdentity()) { $viewRenderer-view-user = $auth-getIdentity(); } } } Cheers, Holger -Original Message- From: Denis Fohl [mailto:[EMAIL PROTECTED] Sent: Tuesday, April 15, 2008 5:21 PM To: fw-general@lists.zend.com Subject: [fw-general] interaction between controller plugin and front controller or view Hi all, i'm learning with zend framework and mvc architecture... and it's hard for me :-) Beause i want it for each controller in my app i made a plugin wich purpose is to test if user is authenticated. I would like it, if true, to pass the info to the view but it does not work, even i user is authenticated, my view var is null. I suppose it's because the view objetc is not yet initialised when the plugin is executed but i can't see where or when to do this. Here is my plugin : class AuthPlugin extends Zend_Controller_Plugin_Abstract { public function preDispatch(Zend_Controller_Request_Abstract $request) { $auth = Zend_Auth::getInstance(); if ($auth-hasIdentity()) { $this-view-user = $auth-getIdentity(); } } } thanks for help -- Denis Fohl -- df-info 06 84 38 21 99