Solved

calling a get-function in Zend Framework

Posted on 2009-07-15
4
941 Views
Last Modified: 2013-11-10
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

0
Comment
Question by:R7AF
  • 2
  • 2
4 Comments
 
LVL 14

Expert Comment

by:profya
ID: 24860942
To use fetchRow method you need to extend Zend_Db_Table_Row_Abstract not Zend_Db_Table_Abstract.
0
 
LVL 13

Author Comment

by:R7AF
ID: 24867541
Sorry, but that doesn't work. And fetchRow is part of Zend_Db_Table_Abstract.
0
 
LVL 13

Accepted Solution

by:
R7AF earned 0 total points
ID: 24868368
I solved it using the following code, analogue to the way I fetch the details from accommodations.
<?php

// Cities.php

class Cities extends Zend_Db_Table_Abstract 

{

	protected $_name = 'cities';

	

	public function fetchDetails($id)

	{

		return $this->fetchRow('id = ' . $id);

	}

}

?>
 

<?php

// AccommodationsController.php

class AccommodationsController extends Zend_Controller_Action

{       

        function detailAction()

        {

                $id = (int) $this->_request->getParam('id');
 

                $view = new Accommodations();

                $row = $view->fetchDetails($id);

                

		$city = new Cities();

		$cityrow = $city->fetchDetails($city_id);

		$this->view->city = $cityrow->name;

        }

}

Open in new window

0
 
LVL 14

Expert Comment

by:profya
ID: 24868446
Yes you are right. Good luck with your own points.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now