开发者

Zend Login Problem

I am new in Zend Framwork. I write a action for login is given below :

public function authAction()
{
    $request = $this->getRequest();
    $registry = Zend_Registry::getInstance();
    $auth = Zend_A开发者_运维技巧uth::getInstance();
    $DB = $registry['rdvs'];
    $authAdapter = new Zend_Auth_Adapter_DbTable($DB);
    $authAdapter->setTableName('user')
                ->setIdentityColumn('user_name')
                ->setCredentialColumn('password');    

    // Set the input credential values
    $uname = $request->getParam('username');
    $paswd = $request->getParam('pwd');
    $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('/service/');
    }else{
      $this->_redirect('/index/');
    }

}

When i rum my web app then its given Exception : Message: No database adapter present I don't understand where i difine database or phpmyadmin connection.


replace

$DB = $registry['rdvs'];

with

$DB = Zend_Db_Table::getDefaultAdapter();

I hope you have setup your db configuration in your application.ini properly if not then

append the following in [production] section of your application.ini and setup the values accordingly like username , password , dbname

resources.db.adapter = PDO_MYSQL
resources.db.isDefaultAdapter = true
resources.db.params.host = localhost
resources.db.params.username = root
resources.db.params.password = 
resources.db.params.dbname = myDbName


It's likely that something is messed up in the registry object. What you can do, instead, is when you create the database connection call Zend_Db_Table_Abstract::setDefaultAdapter($db) instead of putting it into the registry. Most of the components in ZF will look there if a database adapter isn't explicitly given to them.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜