Link to home
Start Free TrialLog in
Avatar of R7AF
R7AFFlag for Netherlands

asked on

calling a get-function in Zend Framework

This is probably an easy question. If I call Cities::getName(), I get the following error. I'm probably using this the wrong way, but I don't see what's wrong. In Eclipse, the method fetchRow does appear.

Fatal error:  Uncaught exception 'Zend_Controller_Action_Exception'
with message 'Method "fetchRow" does not exist and was not trapped in __call()' in D:\web\test\library\Zend\Controller\Action.php:478

Stack trace:
#0 [internal function]: Zend_Controller_Action->__call('fetchRow', Array)
#1 D:\web\test\application\default\models\Cities.php(8): AccommodationsController->fetchRow('id = 2223')
#2 D:\web\test\application\default\controllers\AccommodationsController.php(28): Cities->getName(2223)
#3 D:\web\test\library\Zend\Controller\Action.php(503): AccommodationsController->detailAction()
#4 D:\web\test\library\Zend\Controller\Dispatcher\Standard.php(285): Zend_Controller_Action->dispatch('detailAction')
#5 D:\web\test\library\Zend\Controller\Front.php(934): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#6 D:\web\test\public\index.php(29): Zend_Controller_Front->dispatch()
#7 {main}
thrown in D:\web\test\library\Zend\Controller\Action.php on line 478

<?php
// Cities.php
class Cities extends Zend_Db_Table_Abstract 
{
	protected $_name = 'cities';
	
	function getName($id)
	{
		return $this->fetchRow('id = ' . $id)->name;
	}
}
?>
 
<?php
// AccommodationsController.php
class AccommodationsController extends Zend_Controller_Action
{	
	function detailAction()
	{
		$view = new Accommodations();
		$id = (int) $this->_request->getParam('id');
		$row = $view->fetchDetails($id);
		
		$this->view->city = Cities::getName($id);
	}
}

Open in new window

Avatar of profya
profya
Flag of Sudan image

To use fetchRow method you need to extend Zend_Db_Table_Row_Abstract not Zend_Db_Table_Abstract.
Avatar of R7AF

ASKER

Sorry, but that doesn't work. And fetchRow is part of Zend_Db_Table_Abstract.
ASKER CERTIFIED SOLUTION
Avatar of R7AF
R7AF
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yes you are right. Good luck with your own points.