Create dropdown in cakephp by using option values from database


Posted on 10 Oct 15 by Vickey

By using html helper we can create form elements in i am creating a dropdown in which all option coming from database table

First use html helper in your controller

public $helper = array('Html');

now i am fetching data from database for use this in dropdown

foreach ($Countries as $country) {
$this->set('countrylist', $countrylist);

In  view

<?php echo $this->Form->input('User.country_id',array('type'=>'select','options'=>$countrylist)); ?>


If this post help you reduce time to develop, you can help me to maintain this website :)