ZF-9118: Sample code incorrect in authentication tutorial

Description

Page: http://framework.zend.com/manual/en/…

In the script for authController, lines 8-10 are currently:

08 $loginForm = new Default_Form_Auth_Login($_POST); 09 10 if ($loginForm->isValid()) {

It should probably say

08 $loginForm = new Default_Form_Auth_Login(); 09 10 if ($loginForm->isValid($_POST)) {

Also, the auth/login.phtml refers to $this->form when it should probably refer to $this->loginForm

Comments

Also, line 23 uses $auth, which is not defined anywhere.

Also, (possibly not a bug, just me being a bumbling novice!), $this->_getParam('db') returns null, rather than a DbAdapter object.

I'm attaching this controller/action to the quickstart tutorial code (which seems to use the db adapter without doing any initialisation).

Has anyone figured out the issue with the sample code? If so, please post!

Well, I'm new too and I try to fix the source code as next:

 
$db = Zend_Db_Table_Abstract::getDefaultAdapter();
 
        $loginForm = new Default_Form_Auth_Login($_POST);
 
        if ($loginForm->isValid($_POST)) {
 
            $adapter = new Zend_Auth_Adapter_DbTable(
                $db,
                'utilisateurs',
                'login',
                'mdp',
                'MD5(?)'
                );
 
            $adapter->setCredential($loginForm->getValue('mdp'))
                    ->setIdentity($loginForm->getValue('login'));
 
            $result = $adapter->authenticate($adapter);
 
            if ($result->isValid()) {
                //$this->_helper->FlashMessenger('Successful Login');
                echo "Logged!";
                //$this->_helper->redirector('index');
                return;
            } else {
                echo "Not Logged!";
            }
 
        }
 
        $this->view->loginForm = $loginForm;

Don't forget to initialize the session with a Zend_Session::start(); Also, in the auth/login.phtml, correct $this->form into $this->loginForm

Works here. Hope it helps you ;)

Assigned correct component

I personally added a submit-page check so that 'Value is required and can't be empty' does not get displayed when we first land on the page.

I replaced:



with

as fisharebest said, $auth is not defined!

I had to replace:



with:

on line 27, $this->redirect('/') generated an error (unknown method 'redirect')

I replaced:



with:

Fix in trunk r23868 and merged to branch release 1.11 r23869 - thanks.