Witam
Czy może mi ktoś wytłumaczyć co jest nie tak, albo dlaczego tak to działa?
Chodzi mi konkretnie o metode _forward z klasy Action. Chciałem zrobić łańcuch akcji, wiec dałem na końcu akcji $this->_forward( 'innaAkcja' ). Wszytsko działało ok, do póki nie dodałem uwierzytelniania i autoryzacji. Teraz proces dipatchingu się zapętla i cały czas wykonuje się pierwsza akcja w pętli.Wogóle nie wchodzi do drugiej akcji (
innAkcja).
Autoryzacja jest zrobiona jako plugin do controllera
Kod klasy pluginu:
<?php
class Rhino_Controller_Plugin_Auth extends Zend_Controller_Plugin_Abstract
{
private $_auth;
private $_acl;
private $_noauth = array( 'module' => 'default', 'controller' => 'login',
'action' => 'index');
private $_noacl = array('module' => 'default', 'controller' => 'error',
'action' => 'privileges');
public function __construct($auth, $acl)
{
$this->_auth = $auth;
$this->_acl = $acl;
}
public function preDispatch(Zend_Controller_Request_Abstract $request)
{
if ($this->_auth->hasIdentity()) {
$role = $this->_auth->getIdentity()->getRole();
} else {
$role = 'guest';
}
$controller = $request->controller;
$action = $request->action;
$module = $request->module;
$resource = $controller;
if ( $module != 'default' ) {
$resource = $module . '_' . $controller;
}
if (!$this->_acl->has($resource)) {
$resource = null;
}
if (!$this->_acl->isAllowed($role, $resource, $action)) {
if (!$this->_auth->hasIdentity()) { //nie zalogowany
$module = $this->_noauth['module'];
$controller = $this->_noauth['controller'];
$action = $this->_noauth['action'];
}
else { //zalogowany ale nie ma uprawnien do zasobow
$module = $this->_noacl['module'];
$controller = $this->_noacl['controller'];
$action = $this->_noacl['action'];
}
}
$request->setModuleName($module);
$request->setControllerName($controller);
$request->setActionName($action);
}
}
?>
którego póżniej rejestruje w front controllerze
<?php
$controller->registerPlugin( new Rhino_Controller_Plugin_Auth( $auth, $acl ) );
?>
No i jakieś akcje:
<?php
public function dalejAction ()
{
$this->_forward( 'temp' );
}
public function tempAction()
{
echo '<h1>To jest jakas inna akcja</h1>'; }
?>
Albo może ktoś ma inny pomysł na wykonanie łańcucha akcji ?
----------edit
Po zmianie w klasie pluginu:
<?php
$controller = $request->controller;
$action = $request->action;
$module = $request->module;
?>
na:
<?php
$controller = $request->getControllerName();
$action = $request->getActionName();
$module = $request->getModuleName();
?>
Zadziałało (IMG:
http://forum.php.pl/style_emoticons/default/smile.gif)
Trochę to dziwne, ale ciesze się że ruszyło (IMG:
http://forum.php.pl/style_emoticons/default/smile.gif)
Ten post edytował milus 30.03.2007, 00:21:29