Kousha
Kousha

Reputation: 36219

Zend framework - Run something after the execution of a model

I have a generic model called MyWork_Model_Base that extends Zend_Db_Table_Abstract. All my models then extend MyWork_Model_Base. Is there a way I can add a code to this Model_Base so that it runs every time after the model function is executed?

Thanks

Upvotes: 1

Views: 59

Answers (1)

Nandakumar V
Nandakumar V

Reputation: 4625

You can add the code to the __destruct function of the MyWork_Model_Base class. The destructor will be executed every time the function is executed

class Model_User extends MyWork_Model_Base
{

    public function getUserDetails()
    {
        $select = $this->select();

        $this->column = 'user_id';
        $this->value = '9999';

        return $this->fetchAll($select);
    }

}



class MyWork_Model_Base extends Zend_Db_Table_Abstract
{
  .
  .
  .
  public function fetchAll($select)
  {
    return parent::fetchAll($select);
  }
  public function __destruct()
  {
    echo 'Destruct Called : '.$this->column.'//'.$this->value.' <br/>';
  }
}

Upvotes: 1

Related Questions