Catchable fatal error: Argument 1 passed to Zend_Auth_Adapter_DbTable::__construct()

Discussion in 'Web Design and Development' started by Cabbit, Dec 18, 2009.

  1. Cabbit macrumors 68020

    Cabbit

    Joined:
    Jan 30, 2006
    Location:
    Scotland
    #1
    Trying to build up a login script and this should work however i get a persistent error that crashes the script. I am not quite sure what is causing this. And googling the error reveals what may be answers however there in French/Other so i dinny understand.

    Notice: Undefined index: DB in Sites/dev/application/controllers/LoginController.php on line 34

    Catchable fatal error: Argument 1 passed to Zend_Auth_Adapter_DbTable::__construct() must be an instance of Zend_Db_Adapter_Abstract, null given, called in Sites/dev/application/controllers/LoginController.php on line 36 and defined in Sites/dev/library/Zend/Auth/Adapter/DbTable.php on line 128



    PHP:
    <?php

    /*
        Login Authentication method
    */
    require_once 'Zend/Controller/Action.php';
    require_once 
    'Zend/Auth.php';
    require_once 
    'Zend/Auth/Adapter/DbTable.php';

    class 
    LoginController extends Zend_Controller_Action
    {
        public function 
    indexAction()
        {
            
    /*
                Function displays the login forum
            */
            
    $request $this->getRequest();  
            
    $this->view->assign('action'$request->getBaseURL()."/login/auth");    // Submit buttons action
            
    $this->view->assign('title''Login Form');                                // Page Title
            
    $this->view->assign('username''User Name');                            // Username
            
    $this->view->assign('password''Password');                            // Password
           
    }
           
        public function 
    authAction()
        {
            
    /*
                Login Authentication
            */
            
            
    $request     $this->getRequest();
            
    $registry     Zend_Registry::getInstance();
            
    $auth        Zend_Auth::getInstance(); 
            
            
    $db $registry['DB'];
            
            
    $authAdapter = new Zend_Auth_Adapter_DbTable($db);
            
    $authAdapter->setTableName('users')->setIdentityColumn('username')->setCredentialColumn('password');    
            
            
    /*
                Pass data though validation
            */
            
    $uname $request->getParam('username');
            
    $paswd $request->getParam('password');
            
    $authAdapter->setIdentity($uname);
            
    $authAdapter->setCredential(md5($paswd));
            
            
    /*
                Authenticate the user
            */
            
    $result $auth->authenticate($authAdapter);
            if (
    $result->isValid())
            {
                
    $data $authAdapter->getResultRowObject(null,'password');
                
    $auth->getStorage()->write($data);
                
    $this->_redirect('/index/welcome/');
            }
            else
            {
                
    $this->_redirect('/login/');
            }
        }       
    }
    ?>
     
  2. elppa macrumors 68040

    elppa

    Joined:
    Nov 26, 2003
    #2
    Congratulations.

    Your thread broke the layout of the MacRumours homepage!

    In line 34 of that code $db is assigned a value:
    PHP:
    $db $registry['DB'];
    Then it is passed to the Zend_Auth_Adapter_DbTable constructor:
    PHP:
    $authAdapter = new Zend_Auth_Adapter_DbTable($db);
    Try printing out $db after it is assigned.
    PHP:
    var_dump($db);
    I suspect it is null.

    The error is telling you it should be an instance of Zend_Db_Adapter_Abstract.

    I don't know about Zend so I'm not sure how you initialise an instance of this class, nor how to add it to the registry and assign it to the db key. If “abstract” name means you need to extend it with your own class first and assign an instance of that to the db variable.

    I hope that gives you a starting point in finding the problem (and someone who knows more about Zend can fill in the blanks).
     
  3. Cabbit thread starter macrumors 68020

    Cabbit

    Joined:
    Jan 30, 2006
    Location:
    Scotland
  4. elppa macrumors 68040

    elppa

    Joined:
    Nov 26, 2003
    #4
    Out of interest, can you explain a bit more…?
     

Share This Page