2009年8月11日星期二

Re: [fw-db] Reference DB adaptor from controller

Its hard to say where your database adapter actually is. If you are
using Zend_Application with a application.ini that sets up the db
resource, then you might try something like this:

// inside a controller action
$this->getParam('bootstrap')->getPluginResource('db')->getDbAdapter()

This will return the dbAdapter object that would have been setup with
Zend_Application and configured in your application.ini.

If you are not using Zend_Application, you should be setting up your db
adapter in your bootstrap.php file, then putting it inside your
Zend_Registry for later use.

Hope that helps,
Ralph

Steve Rayner wrote:
> I'm still struggling to get Zend_Auth to work.
>
>
>
> I understand i need to get a reference to my database adaptor, but i don't
>
> know how to do that. This is my code;
>
>
>
> public function getAuthAdapter(array $params)
>
> {
>
>
>
> $db = Zend_Registry::get('defaultDb');
>
> $authAdapter = new Zend_Auth_Adapter_DBTable(
>
> $db,
>
> 'USERS',
>
> 'USERNAME',
>
> 'PASSWORD'
>
> );
>
>
>
> // Set the input credential values (e.g., from a login form)
>
> $authAdapter->setIdentity($params['username'])
>
> ->setCredential($params['password']);
>
>
>
>
>
> return $authAdapter;
>
>
>
> }
>
>
>
> It throws an error;
>
>
>
> Zend_Exception: No entry is registered for key 'defaultDb'
>
>
>
> I also tried the key as being just 'db' but that throws the same error.
>
> Any help apreciated.
>
>
>
> Steve
>
>
>
> Williams Refrigeration is a trading name of AFE Group Limited.
> Registered in England & Wales under Registered Number 3872673. Registered
> Office Address - Bryggen Road, North Lynn, Industrial Estate, Kings
> Lynn, Norfolk, PE30 2HZ
>
> Williams Refrigeration reserves the right to block any email attachment
> we deem inappropriate and to also reject any inbound connections from
> Blacklisted servers. Any email meeting the above criteria will be
> automatically rejected without notification given to the original sender.
>
> NOTE: In accordance with the Data Protection Act compliance, all Bulk
> sends should use the BCC field as much as possible.
>
> This e-mail and any files transmitted with it are confidential and
> intended solely for the use of the individual or entity to whom they are
> addressed. If you have received this email in error or are having
> trouble sending email to Williams please notify the system administrator
> - postmaster@williams-refrigeration.co.uk
>
> Any views or opinions expressed in this e-mail are those of the sender
> and do not necessarily coincide with those of Williams Refrigeration or
> the AFE Group.

没有评论: