print_r($products);
返回:
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 )
** ......错了。它必须是**
[1] => product_item_1,
[2] => product_item_2, ....etc.....
为什么数组错了?
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(型号):
`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));
这个下拉列表包含13个项目,这是正确的,但它是空的....为什么?
答案 0 :(得分:2)
我没看到字段
$products=$this->Product->find('list',
array('fields' => array('Product.id','Product.product_name')));