Can i override fetchall method in a model? I need to check sth everytime fetchAll is called. The model extends Zend_db_table_abstract
+9
A:
To override this method you would need to subclass the Zend_Db_Table_Abstract. Like so:
<?php
abstract class My_Db_Table_Abstract extends Zend_Db_Table_Abstract
{
...
public function fetchAll($where, $order)
{
...
}
...
}
Then make sure your models extend My_Db_Table_Abstract instead. This way, you will always inherit your overridden fetchAll method.
Kieran Hall
2008-10-13 16:02:15
Since you're naming it `Abstract`, you probably want it to be an `abstract class`.
chelmertz
2009-11-20 01:52:46
Yes, you're right. I've updated the example. Thanks.
Kieran Hall
2009-11-20 14:26:53
A:
Yes. Just define a new fetchAll() method in your model with the same construction as the Zend_db_table_abstract method (ie same input / output) then at the end of your method call the parent method:
parent::fetchAll($params)
Andrew
Andrew Taylor
2008-10-23 13:33:32