-- Mauro Casula <[EMAIL PROTECTED]> wrote
(on Monday, 13 November 2006, 02:55 AM -0800):
> I'm new of Zend Framework..
>
> I need your help. I need to know how can i now what
> Zend_Controller_Dispatcher_Token i'm going to dispatch in my Index.php.
First off, if you're new to ZF, don't use the controller classes in
core, use those in the incubator, as they are the next generation and
will be moved to core in the next release.
> I need to know this because i'm developing an authentication system that
> will make the following:
> $controller = Zend_Controller_Front::getInstance();
> //AuthenticationController is my authentication class
> $auth = AuthenticationController::factory($db,$session,$controller);
>
> // if i have to authenticate:
> $username = trim($post->noTags('username'));
>
> if ($username!='') {
> $password= trim($post->noTags('password'));
> $auth->login($username, $password);
> }
>
> // i control from my class if the $token need authentication
> // when the user is authenticated .. authRequired return false.
>
>
> if ($auth->authRequired($token) == true) {
> // I store in Session where i was going..
> $session->__set('token',$token);
> // I go to /login/login for display a form and put username
> and password...
> $dispacher = new Zend_Controller_Dispatcher();
> $token = new Zend_Controller_Dispatcher_Token ("Login","login");
> $dispacher->setControllerDirectory('../app/controllers');
> $dispacher->dispatch($token);
> }
Simon Mundy gave a great example of how to integrate authentication with
the MVC components recently. Basically, you want to do the following:
* Create a Plugin class extending Zend_Controller_Plugin_Abstract,
and specifically override the preDispatch() method
* Place your authentication criteria in the preDispatch() method:
* Check against $this->getRequest()->getControllerName() and
$this->getRequest()->getActionName() when validating an action
against the credentials:
$request = $this->getRequest();
$controller = $request->getControllerName();
$action = $request->getActionName();
$if (!$auth->authRequired($controller, $action)) {
// all okay...
} else {
// need authentication...
}
* Do the following if you need the user to login:
$request = $this->getRequest();
$request->setControllerName('login')
->setActionName('login')
->setDispatched(false);
Then, in your bootstrap (index.php), do the following:
$controller = new Zend_Controller_Front();
$controller->registerPlugin(new My_Controller_Plugins())
->setParam('session', $session)
->setParam('db', $db)
->setControllerDirectory('../app/controllers');
$controller->dispatch();
--
Matthew Weier O'Phinney
PHP Developer | [EMAIL PROTECTED]
Zend - The PHP Company | http://www.zend.com/