Deprecated generateList in CakePHP 1.2


I’m trying to use generateList function in CakePHP 1.2 but I got a line of error message that said generateList function was deprecated.
Here is the error message detail

<span><span>Warning (512): (Model::generateList) Deprecated, </span><span class="keyword">use</span><span> Model::find(</span><span class="string">"list"</span><span>) </span><span class="keyword">or</span><span> Model::find(</span><span class="string">"all"</span><span>) </span><span class="keyword">and</span><span> Set::combine() [CORE\cake\libs\model\model.php, line 2191]  

So I take a look to cake-php mailing list and found a solution that work fine for my need at the time, here is the example code:

In the controller I put line like the following:

// /app/controllers/customers_controller.php
$customers =$this->Customer->find("all",array('fields'=>array('Customer.customer_name','Customer.id'),'order'=>'Customer.customer_name ASC'));
$cust_combine = Set::combine($customers, '{n}.Customer.id','{n}.Customer.customer_name');
$this->set('customers', $cust_combine);

I want to explain a litte here that you may change fields to suit with your environment,
in above code I put Customer.customer_name and Customer.id because I just need that two field in my form
then in line Set::combine($customers, ‘{n}.Customer.id’,’{n}.Customer.customer_name’);
I want to make Customer.id as the key and Customer.customer_name as the value.

Here is the code I put in view

// /app/views/customers/index.php
print 'Customer:'. $form->select('Customer/id', $customers, $html->Value('Customer/id'), array('class'=>'select large'), array(), true);

Information and Links

Join the fray by commenting, tracking what others have to say, or linking to it from your blog.


Other Posts
Using ExtJS form integrated with CakePHP
Hello world!

Write a Comment

Take a moment to comment and tell us what you think. Some basic HTML is allowed for formatting.

Reader Comments

While you can do a find(’all’) and Set::combine, I think it is more succinct to use find(’list’).

$customers = $this->Customer->find(”list”,array(’fields’=>array(’Customer.id’,'Customer.customer_name’),’order’=>’Customer.customer_name ASC’));

Thank you psa and thank you Grant. Solved my problem. Gotta bump this post in google. FYI, baking scripts still uses generateList

You could use this in cake php 1.2

#
$customers =$this->Customer->find(”list”,array(’fields’=>array(’Customer.customer_name’,'Customer.id’),’order’=>’Customer.customer_name ASC’));

#
$this->set(’customers’, $customers);