Jump to content

how to extend a method in a extended class


nadeemshafi9

Recommended Posts

hi guys

 

i am extending the zend_db_table class to make it work with a clustered db system.

 

in the child class i would like to overide a method yet preserv the parents method proceedure.

 

i owuld like to log stuff in update yet call the parents update method.

 

is this possible ?

 

how do you call a parents method ??? parent::blah blah i dont know any ideas ???

 

thanks guys

class My_Db_Table extends Zend_Db_Table
{
    public function overwriteMethod() {
        //do something
        parent::overwriteMethod();
    }
}

 

will i be able to include the parent methods proceedure this way or do i have to call it parent::mthod();, thnx btw

class My_Db_Table extends Zend_Db_Table
{
    public function overwriteMethod() {
        //do something
        parent::overwriteMethod();
    }
}

 

will i be able to include the parent methods proceedure this way or do i have to call it parent::mthod();, thnx btw

 

No you won't. Zend framework doesn't entirely come without it flaws, and one of the main complaints are what you are experiencing. You still need to copy-paste a serious amount of code to add some more functionality. The reason for this is because Zend framework is still in a serious development process and they don't intend to re-factor any code anytime soon. But eventually you'll be able to extend their code base without copy-pasting.

i managed to do it

 

public function delete($where){
	$r = parent::delete($where);
    	$model 					= $this->_getModel();
    	$user 					= Zend_Registry::get('user');
    	$dbAdapters 			= Zend_Registry::get('dbAdapter');
    	$db 					= $dbAdapters['server1'];
    	$irh_user_transactions 	= $model->getTable("irh_user_transactions");
    	$profiler 				= $db->getProfiler();
    	$query					= $profiler->getLastQueryProfile();
    	$params 				= "";
    	
	foreach($query->getQueryParams() as $p){
		$params .= "'{$p}',";
	}

    	$data = array(
		'user_id'		=> $user->user_id,
		'transaction'	=> "QUERY: {$query->getQuery()} || PARAMS: {$params} || TIME: {$query->getElapsedSecs()}"
	);

	try{
	    $irh_user_transactions->logException = true;
		if(!$this->logException) $irh_user_transactions->insert($data);
	}
	catch(Zend_Db_Table_Exception $e){
	    die($e);	
	}

	return $r;
}

public function update(array $data, $where){
    	$r = parent::update($data, $where);
    	$model 					= $this->_getModel();
    	$user 					= Zend_Registry::get('user');
    	$dbAdapters 			= Zend_Registry::get('dbAdapter');
    	$db 					= $dbAdapters['server1'];
    	$irh_user_transactions 	= $model->getTable("irh_user_transactions");
    	$profiler 				= $db->getProfiler();
    	$query					= $profiler->getLastQueryProfile();
    	$params 				= "";
    	
	foreach($query->getQueryParams() as $p){
		$params .= "'{$p}',";
	}

    	$data = array(
		'user_id'		=> $user->user_id,
		'transaction'	=> "QUERY: {$query->getQuery()} || PARAMS: {$params} || TIME: {$query->getElapsedSecs()}"
	);

	try{
	    $irh_user_transactions->logException = true;
		if(!$this->logException) $irh_user_transactions->insert($data);
	}
	catch(Zend_Db_Table_Exception $e){
	    die($e);	
	}

	return $r;
    }
public function insert(array $data){
    	$r = parent::insert($data);
    	$model 					= $this->_getModel();
    	$user 					= Zend_Registry::get('user');
    	$dbAdapters 			= Zend_Registry::get('dbAdapter');
    	$db 					= $dbAdapters['server1'];
    	$this->lastInsertId 	= $db->lastInsertId();
    	$irh_user_transactions 	= $model->getTable("irh_user_transactions");
    	$profiler 				= $db->getProfiler();
    	$query					= $profiler->getLastQueryProfile();
    	$params 				= "";
    	
	foreach($query->getQueryParams() as $p){
		$params .= "'{$p}',";
	}

    	$data = array(
		'user_id'		=> $user->user_id,
		'transaction'	=> "QUERY: {$query->getQuery()} || PARAMS: {$params} || TIME: {$query->getElapsedSecs()}"
	);

	try{
	    $irh_user_transactions->logException = true;
		if(!$this->logException) $irh_user_transactions->insert($data);
	}
	catch(Zend_Db_Table_Exception $e){
	    die($e);	
	}

	return $r;
    }

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.