tomas3man
tomas3man

Reputation: 29

Array is empty, relation one to many, cakephp

print_r($products);

Returns:

Array ( [1] => 1 [2] => 2 [3] => 3 [4] => 4 [5] => 5 [6] => 6 [7] => 7 [8] => 8 [9] => 9 [10] => 10 [11] => 11 [12] => 12 [13] => 13 )

**...is wrong. It have to be **

[1] => product_item_1, 
[2] => product_item_2, ....etc.....

Why array is wrong?

KlientsController.php:

class KlientsController extends AppController {
     var $name = 'Klients';
     var $scaffold;

public $helpers = array('Html', 'Form', 'Session', 'Form');
public $components = array('Session');

  public function newedit($id = null) {
      $this->Klient->recursive = 1;
      $this->loadModel('Product');
      $products=$this->Product->find('list',
                array('Product.id','Product.product_name'));    

Klient.php (model):

   `class Klient extends AppModel {
       var $name = 'Klient';
        var $belongsTo = array('Product');

 function newedit($id = null){    
        $products = $this->Klient->Product->generateList();       
        $this->set('products', $products);

}

newedit.ctp:

 echo $this->Form->input('product_id', 
                 array('options' => $products));

This drop down list contains 13 items, that's correct, but it is empty....why?

Upvotes: 0

Views: 48

Answers (1)

CoolLife
CoolLife

Reputation: 1479

I don't see the field

$products=$this->Product->find('list',
              array('fields' => array('Product.id','Product.product_name')));    

Upvotes: 2

Related Questions