robos85
unread,Oct 8, 2009, 10:49:24 AM10/8/09Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Zend Framework Developers
Hi, I'm starting to learn the Zend FM. I'm making some tutorials for
1.8 (i'm using 1.9).
I stuck on error:
Notice: Trying to get property of non-object in C:\wamp\www\dziury
\application\plugins\AccessCheck.php on line 19
Line 19: $role = $identity->role;
My files:
Bootstrap.php:
<?php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
protected function _initAutoload()
{
$modelLoader = new Zend_Application_Module_Autoloader
(array(
'namespace' => '',
'basePath' =>
APPLICATION_PATH
));
$acl = new Model_LibraryAcl; // obiekt modelu do ACL
potrzebny do przekazania do pluginu
$auth = Zend_Auth::getInstance(); // obiekt modelu do
AUTH potrzebny do przekazania do pluginu
$fc = Zend_Controller_Front::getInstance(); //
instancja - umożliwia ładowanie pluginów
$fc->registerPlugin( new Plugin_AccessCheck($acl,
$auth) ); // rejestruje plugin. Przekazać 2 zmienne potrzebne do
sprawdzenia
return $modelLoader;
}
}
plugins/AccessCheck.php:
class Plugin_AccessCheck extends Zend_Controller_Plugin_Abstract
{
private $_acl = null;
private $_auth = null;
public function __construct( Zend_Acl $acl, Zend_Auth $auth )
{
$this->_acl = $acl;
$this->_auth = $auth;
}
public function preDispatch( Zend_Controller_Request_Abstract
$request ) // musimy poznać jaki aktualnie jest kontroler. Robimy to
dzięki Zend_Controller_Request_Abstract i przypisujemy do zmiennej
$request
{
$resource = $request->getControllerName(); // nazwa
kontrolera
$action = $request->getActionName(); // akcja
$identity = $this->_auth->getStorage()->read(); // pobieramy i
odczytujemy dane z Auth odnośnie informacji o userze
$role = $identity->role; // pobranie roli. role to nazwa pola
z bazy
if( !$this->_acl->isAllowed($role, $resource, $action) ) //
sprawdzenie zgodności z warunkami w modelu acl
{
$request->setControllerName('authentication') //
ustawienie nazwy kontrolera
->setActionName('login'); // ustawienie nazwy
akcji
}
}
}
How to fix that?