You might be better off using the defining an init() method instead of
overwriting the constructor:
class Account extends Zend_Db_Table_Abstract
{
protected $_name = 'account';
public function init()
{
$this->_acc = $this->getCurrentAccount();
}
/* ... */
}
The advantage is that you can still use the default constructor for
overwriting values on instantiation:
$table = new Account(array('schema' => 'other_schema'));
and you also won't run into problems with strict PHP5 errors (you can't
remove arguments from a method when redefining it in a base class).
--
Hector
On Mon, Apr 12, 2010 at 6:52 AM, Alayn Gortazar <[email protected]> wrote:
> Yo need to call parent's costructor to initialize the object before
> using the find method.
>
> I think the constructor doesn't return any value, so this should work:
>
> public function __construct()
> {
> parent::__construct();
> $this->_acc = $this->getCurrentAccount();
> }
>
> lun, 12-04-2010 a las 05:29 -0800, milesap escribió:
> > I have an account model like so:
> >
> > <?php
> >
> > class Account extends Zend_Db_Table_Abstract
> > {
> > protected $_name = 'account';
> >
> > public function __construct()
> > {
> > $this->_acc = $this->getCurrentAccount();
> > return parent::__construct();
> > }
> >
> > public function getCurrentAccount()
> > {
> > $auth = Zend_Auth::getInstance();
> > $data = $auth->getIdentity();
> > return $this->find($data['id'])->current();
> > }
> > . . . more
> > }
> >
> > and a create account model which extends the account model:
> >
> > class Account_Create extends Account
> > {
> > public function __construct()
> > {
> > return parent::__construct();
> > }
> > . . . more
> > }
> >
> > I get the following error message:
> > Fatal error: Call to a member function describeTable() on a non-object
> in
> > /Applications/MAMP/Library/Zend/Db/Table/Abstract.php on line 814
> >
> > I know for a fact that this error is caused by the __construct method, if
> I
> > remove the line '$this->_acc = $this->getCurrentAccount();' the error
> goes
> > away. Am I doing anything wrong here? Thanks so much!
> >
> >
>
> --
> Alayn Gortazar
> Irontec, Internet y Sistemas sobre GNU/LinuX - http://www.irontec.com
> +34 94.404.81.82
>
>
>