adding “select here” in cakephp dropdown

Standard

We all know that to get a list in CakePHP it is very simple. Just $this->Model->find(‘list’) will do. But then the irritating thing is cake will just list down everything and on the first option on the drop down list you will see the first record of the list, which should not be it. Normally you should see “Select Here” on top instead.

To solve it, do it this way:

$clients = array(” => ‘Select Client’) + $this->Client->find(‘list’);
$products = array(” => ‘Select Product’) + $this->Product->find(‘list’);
$this->set(compact(‘clients’, ‘products’));

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s