Jump to content

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;
    }

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.