Solved

How can I populate a drop down (<select>) using cakePHP via MySql database

Posted on 2008-10-16
4
9,043 Views
Last Modified: 2013-12-13
I am trying to find out how to populate a HTML select object using CakePHP with a MySQL database? Say I want to fill in categories from my categories database, to keep it dynamic? Any ideas?

Thanks,

Ryan
0
Comment
  • 2
4 Comments
 
LVL 10

Accepted Solution

by:
wildzero earned 500 total points
ID: 22749439
Hi there,

In your controller's action you need to select all the items you want, and then send them to the view
$options = $this->Categories->find('all');
$this->set('options', $options);

Then in the view you can use the form helper like
<?php $form->input('categories' => array('options' => $options)); ?>

Thats pretty rough, but it should give you a good idea :-)
0
 
LVL 10

Expert Comment

by:wildzero
ID: 22749447
Take a look at this
http://groups.google.com/group/cake-php/browse_thread/thread/475236491480fb3d/d12c1baf5cf1f751
pretty much the same question you have, and Wayne Madison writes a pretty good reply
0
 
LVL 1

Author Comment

by:catonthecouchproductions
ID: 22778966
Thank you! I want to keep playing with Cake to build some apps! I feel like when you understand it you can start to develp apps on the fly or well i should say much faster than traditional PHP.

Ryan
0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

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 …
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
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…
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…

805 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