Umme Raihana
Umme Raihana

Reputation: 41

How to change cakephp default value in select List?

I need to change cakephp default value from select box.Here in controller I have coded

$madDivisions = $this->MadStore->MadDivisions->find('list');

In view

<?php
      echo $this->Form->input('mad_divisions_id',array( 'label' => false, 'class'=>'form-control','id'=>'select' ));
?>

After add jquery val() method

<script>
    $('#select').change(function(){
        var a=$('#select').val();
        alert(a);
    })
</script>

It showing me 1,2......

But I want to change this default value and want to replace divisions name as a value.Like as

<option value="London">London</option>
<option value="Dhaka">Dhaka</option>

Upvotes: 1

Views: 885

Answers (2)

Pankaj Badukale
Pankaj Badukale

Reputation: 2046

Try this for find method with list

    $madDivisions = $this->MadStore->MadDivisions->find(    'list', 
                                                            array(
                                                                    'fields' => array(
                                                                                    'city_name', 
                                                                                    'city_name'
                                                                                )
                                                            )
                                                        );

city_name is the column name from database table which contains values for London, Dhaka.

Upvotes: 2

Colonel Mustard
Colonel Mustard

Reputation: 1533

$this->MadStore->MadDivisions->find('list'); will return a list of results based on the $displayField you have set in the model. You possibly have the $displayField set as the id of the table or it may not be set at all. Change this to whatever field that you want returned in a list. cakephp find list more info

Upvotes: 1

Related Questions