Results 1 to 2 of 2

Thread: Catchable fatal error

  1. #1
    sumesh is offline Junior Member
    Join Date
    Jun 2009
    Posts
    1

    Thumbs up Catchable fatal error

    Hi all,
    please help me to solve this problem

    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 /var/www/schoolslp/application/controllers/UserController.php on line 38 and defined in /var/www/schoolslp/library/Zend/Auth/Adapter/DbTable.php on line 128

    this is the controller

    <?php

    require_once 'Zend/Controller/Action.php';
    require_once 'Zend/Auth.php';
    require_once 'Zend/Auth/Adapter/DbTable.php';

    class UserController extends Zend_Controller_Action
    {

    public function indexAction()
    {
    $registry = Zend_Registry::getInstance();

    $title = $registry['title'];
    $credits = $registry['credits'];
    $strCredit = implode(", ",$credits);

    $this->view->assign('name', 'Wiwit');
    $this->view->assign('title', $title);
    $this->view->assign('credits', $strCredit);
    }

    public function loginformAction()
    {
    $request = $this->getRequest();
    $this->view->assign('action', $request->getBaseURL()."/user/auth");
    $this->view->assign('title', 'Login Form');
    $this->view->assign('username', 'User Name');
    $this->view->assign('password', 'Password');

    }

    public function authAction(){
    $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');

    // Set the input credential values
    $uname = $request->getParam('username');
    $paswd = $request->getParam('password');
    $authAdapter->setIdentity($uname);
    $authAdapter->setCredential(md5($paswd));

    // Perform the authentication query, saving the result
    $result = $auth->authenticate($authAdapter);

    if($result->isValid()){
    //print_r($result);
    $data = $authAdapter->getResultRowObject(null,'password');
    $auth->getStorage()->write($data);
    $this->_redirect('/user');
    }else{
    $this->_redirect('/user/loginform');
    }

    }


    public function nameAction()
    {

    $request = $this->getRequest();
    $this->view->assign('name', $request->getParam('username'));
    $this->view->assign('gender', $request->getParam('gender'));

    $this->view->assign('title', 'User Name');
    }

    public function registerAction()
    {
    $request = $this->getRequest();

    $this->view->assign('action',"process");
    $this->view->assign('title','Member Registration');
    $this->view->assign('label_fname','First Name');
    $this->view->assign('label_lname','Last Name');
    $this->view->assign('label_uname','User Name');
    $this->view->assign('label_pass','Password');
    $this->view->assign('label_submit','Register');
    $this->view->assign('description','Please enter this form completely:');
    }

    public function editAction()
    {
    $registry = Zend_Registry::getInstance();
    $DB = $registry['DB'];

    $request = $this->getRequest();
    $id = $request->getParam("id");

    $sql = "SELECT * FROM `users` WHERE id='".$id."'";
    $result = $DB->fetchRow($sql);

    $this->view->assign('data',$result);
    $this->view->assign('action', $request->getBaseURL()."/user/processedit");
    $this->view->assign('title','Member Editing');
    $this->view->assign('label_fname','First Name');
    $this->view->assign('label_lname','Last Name');
    $this->view->assign('label_uname','User Name');
    $this->view->assign('label_pass','Password');
    $this->view->assign('label_submit','Edit');
    $this->view->assign('description','Please update this form completely:');
    }

    public function processAction()
    {

    $registry = Zend_Registry::getInstance();
    $DB = $registry['DB'];

    $request = $this->getRequest();
    $data = array('first_name' => $request->getParam('first_name'),
    'last_name' => $request->getParam('last_name'),
    'user_name' => $request->getParam('user_name'),
    'password' => md5($request->getParam('password'))
    );
    $DB->insert('user', $data);

    $this->view->assign('title','Registration Process');
    $this->view->assign('description','Registration succes');

    }

    public function listAction()
    {

    $registry = Zend_Registry::getInstance();
    $DB = $registry['DB'];

    $sql = "SELECT * FROM `user` ORDER BY user_name ASC";
    $result = $DB->fetchAssoc($sql);

    $this->view->assign('title','Member List');
    $this->view->assign('description','Below, our members:');
    $this->view->assign('datas',$result);

    }

    public function processeditAction()
    {

    $registry = Zend_Registry::getInstance();
    $DB = $registry['DB'];

    $request = $this->getRequest();

    $data = array('first_name' => $request->getParam('first_name'),
    'last_name' => $request->getParam('last_name'),
    'user_name' => $request->getParam('user_name'),
    'password' => md5($request->getParam('password'))
    );
    $DB->update('user', $data,'id = '.$request->getParam('id'));

    $this->view->assign('title','Editing Process');
    $this->view->assign('description','Editing succes');

    }

    public function delAction()
    {
    $registry = Zend_Registry::getInstance();
    $DB = $registry['DB'];

    $request = $this->getRequest();

    $DB->delete('user', 'id = '.$request->getParam('id'));

    $this->view->assign('title','Delete Data');
    $this->view->assign('description','Deleting succes');
    $this->view->assign('list',$request->getBaseURL()."/user/list");

    }

    }
    ?>

  2. #2
    mark2331 is offline Senior Member
    Join Date
    Oct 2008
    Location
    Los Angeles, CA
    Posts
    176

    Default

    public function authAction(){
    $request = $this->getRequest();
    $registry = Zend_Registry::getInstance();
    $auth = Zend_Auth::getInstance();
    $DB = $registry['DB'];
    $authAdapter = new Zend_Auth_Adapter_DbTable($DB);
    maybe you didn't add your $DB object to the registry correctly.

    try
    [PHP]$DB = Zend_Db_Table_Abstract::getDefaultAdapter();[/PHP]

    and see if it works. you should be able to see the object's properties if you do a [PHP]var_dump($DB);[/PHP] then if you want to add the $DB object to the registry after you confirmed it indeed worked.
    [PHP]$DB = Zend_Registry::set('DB', $DB);[/PHP]

    but if do a [PHP]var_dump($DB);[/PHP] and it returns null, then you haven't set your default database adapter.
    Last edited by mark2331; 06-16-2009 at 04:03 PM.

Similar Threads

  1. weird fatal error but only on one server
    By edmondscommerce in forum Installation & Configuration
    Replies: 3
    Last Post: 07-10-2009, 03:39 PM
  2. Fatal Error
    By SadClown in forum General Q&A on Zend Framework
    Replies: 2
    Last Post: 12-29-2008, 09:25 PM
  3. Fatal error in Zend_Db_Table_Abstract
    By Sunshine in forum Databases
    Replies: 2
    Last Post: 12-04-2008, 04:00 PM
  4. CSS and Fatal Error problem
    By mhmtlgrr in forum General Q&A on Zend Framework
    Replies: 0
    Last Post: 06-15-2008, 12:16 PM
  5. HTTT 500 error code when Fatal Error happens
    By Georgy in forum General Q&A on Zend Framework
    Replies: 0
    Last Post: 10-23-2007, 12:32 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •