Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to get FetchAll() to return an array in Zend Framework

Posted on 2008-06-26
3
Medium Priority
?
6,515 Views
Last Modified: 2013-12-12
HI,
     I'm trying to populate a Select aka dropdown in a form.  I have an error that tells me I'm not sending the select an array.  What am I doing wrong.

Catchable fatal error: Argument 1 passed to Zend_Form_Element_Multi::setMultiOptions() must be an array, object
$sites = new Sites();
        $sitelist = $sites->getsitelist();
               
        $site = new Zend_Form_Element_Select('site');
        $site->setLabel('Site')
        ->setRequired(true)
        ->addValidator('NotEmpty', true)
        ->setMultiOptions($sitelist);
 
 
 
 
------------------------------------------------------------------------------------------------------------
 
 
 
class Sites extends Zend_Db_Table_Abstract {
	/**
	 * The default table name 
	 */
	protected $_name = 't_sites';
	
	public function getsitelist()
	{
		
		$sites =new Sites();
		
		return $sites->fetchAll(array('id = id', 'name = name'));
		
	}
 
}

Open in new window

0
Comment
Question by:sean-keys
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 9

Accepted Solution

by:
Rurne earned 2000 total points
ID: 21877849
Couple of things I see.

1.  line 28 is a bit confusing... 'id = id' and 'name = name' are reflexive, so this should always match.
2.  fetchAll returns Zend_Db_Rowset_Abstract, not an array.  You can use the toArray() function to break out of the Rowset object... change line 8 to:

->setMultiOptions($sitelist->toArray());
0
 

Author Comment

by:sean-keys
ID: 21877978
If you are confused there is no hope for me, jk.  

      return $sites->fetchAll()->toArray();     Worked.

But it filled the dropdown with every columns data as a choice , not a rowset.

0
 

Author Comment

by:sean-keys
ID: 21878065
The blunder at line 28 was an attempt to get one row to show up per selection in the dropdown.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
This article discusses how to implement server side field validation and display customized error messages to the client.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

670 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