ZF-9118: Sample code incorrect in authentication tutorial

Issue Type: Docs: Problem Created: 2010-02-08T15:38:14.000+0000 Last Updated: 2011-04-23T22:12:39.000+0000 Status: Resolved Fix version(s): - 1.11.6 (05/May/11)

Reporter: fisharebest (fisharebest) Assignee: Ramon Henrique Ornelas (ramon) Tags: - Zend_Auth

Related issues: Attachments:



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


Posted by fisharebest (fisharebest) on 2010-02-08T16:08:21.000+0000

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).

Posted by PVWebGuy (cewolfe) on 2010-02-17T10:27:17.000+0000

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

Posted by Menencia (menencia) on 2010-03-02T23:29:34.000+0000

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

<pre class="highlight"> 
$db = Zend_Db_Table_Abstract::getDefaultAdapter();
        $loginForm = new Default_Form_Auth_Login($_POST);
        if ($loginForm->isValid($_POST)) {
            $adapter = new Zend_Auth_Adapter_DbTable(
            $result = $adapter->authenticate($adapter);
            if ($result->isValid()) {
                //$this->_helper->FlashMessenger('Successful Login');
                echo "Logged!";
            } 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 ;)

Posted by Thomas Weidner (thomas) on 2010-03-15T11:23:08.000+0000

Assigned correct component

Posted by Remy Damour (remy215) on 2010-04-29T10:03:39.000+0000

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:

<pre class="highlight">


Posted by Remy Damour (remy215) on 2010-04-29T11:35:47.000+0000

as fisharebest said, $auth is not defined!

I had to replace:

<pre class="highlight">


Posted by Remy Damour (remy215) on 2010-04-29T12:07:21.000+0000

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

I replaced:

<pre class="highlight">


Posted by Ramon Henrique Ornelas (ramon) on 2011-04-23T22:12:39.000+0000

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

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.