Jump to content

OOP method extend help


nadeemshafi9

Recommended Posts

hello guys

 

i am trying to extend a method of a class but i am getting

 

ERROR: declaration of Model Db Cluster::update() should be compatible with that of Zend_Db_Table_Abstract::update() in <b>/var/websites/irh.net/application/models/DbCluster.php 

 

i reflected the parent and made sure my signiture was correct

<?php
class Model_DbCluster extends Zend_Db_Table
{
    /** Model_Table_Inventory
     * 	List your tables that this model can reference here... 
     * */
    protected $_table;
protected $_name    		= 'hosts_inventory';
protected $_schema			= 'irh_tftp';  		// database name
protected $_mode;

public function getTable($name)
    {
    	//add2debug("DBCLUSTER getTable called for [$name]");
    	
    	$_name = $name;
    	$_model = "table_$name";
    	
    	//add2debug("NULL CHECK [this -> $_name]");
        if (null === @$this->$_name) // supress the error if it doesnt exist yet
        {
            // since the dbTable is not a library item but an application item,
            // we must require it to use it
            require_once APPLICATION_PATH . "/models/DbTable/$name.php";
            $this->$_name = new $_model;
        }

        return $this->$_name;
    }
public function update($data , $where){
    	$r = parent::update();
    	$user 					= Zend_Registry::get('user');
    	$dbAdapters 			= Zend_Registry::get('dbAdapter');
    	$db 					= $dbAdapters['server1'];
    	$model 					= $this->_getModel();
    	$irh_user_transactions 	= $model->getTable("irh_user_transactions");
    	$profiler 				= $db->getProfiler();
    	$profile				= $profiler->getLastQueryProfile();
    	
    	$data = array(
		'user_id'		=> $user->user_id,
		'transaction'	=> $profile
	);

	try{
	    $irh_user_transactions->insert($data);
	}
	catch(Zend_Db_Table_Exception $e){
	    $e;	
	}

        // the parent returns so iu thoght id catch it and return that 	
return $r;
    }
    
    protected function _getModel()
    {
    	try {$this->_model = Zend_Registry::get('irhModel');} catch (Exception $exception) {$this->_model = null;}
        if (null === $this->_model) 
        {
            // autoload only handles "library" components.  Since this is an 
            // application model, we need to require it from its application 
            // path location.
            require_once APPLICATION_PATH . '/models/DbCluster.php';
            $c = __CLASS__;
            $this->_model = new $c;
            Zend_Registry::set('irhModel',$this->_model);
        }
        return $this->_model;
    }
}

 

 

thanks for any help im just starting at this level of oop

Link to comment
Share on other sites

<?php
abstract class App_Db_Table_Abstract extends Zend_Db_Table_Abstract{
function App_Db_Table_Abstract($config = null){
	if(isset($this->_use_adapter))
	{
		$dbAdapters = Zend_Registry::get('dbAdapter');
		$config = ($dbAdapters[$this->_use_adapter]);
	}
	return parent::__construct($config);
}

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->insert($data);
	}
	catch(Zend_Db_Table_Exception $e){
	    die($e);	
	}

	return $r;
    }

    protected function _getModel()
    {
    	try {$this->_model = Zend_Registry::get('irhModel');} catch (Exception $exception) {$this->_model = null;}
        if (null === $this->_model) 
        {
            // autoload only handles "library" components.  Since this is an 
            // application model, we need to require it from its application 
            // path location.
            require_once APPLICATION_PATH . '/models/DbCluster.php';
            $this->_model = new Model_DbCluster();
            Zend_Registry::set('irhModel',$this->_model);
        }
        return $this->_model;
    }
}

Link to comment
Share on other sites

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.