Solved

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

Posted on 2008-06-26
3
6,398 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
  • 2
3 Comments
 
LVL 9

Accepted Solution

by:
Rurne earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
The blunder at line 28 was an attempt to get one row to show up per selection in the dropdown.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
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 …
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…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

771 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

11 Experts available now in Live!

Get 1:1 Help Now