在将 1.3 CakePHP 应用程序升级到 2.2.5 的过程中,我在find('list')
.
有谁知道为什么我的id
值是 1 而不是存储在数据库中的增量值,即 1、2、3、4、5?
当我运行控制器代码(如下所示)时,我得到:
Array
(
[1] => 5
)
我想要得到的是:
Array
(
[1] => 1 (urgent)
[2] => 2
[3] => 3
[4] => 4
[5] => 5
)
如果我将其更改为find('all')
,我会得到:*请注意,该[id]
值始终为 1 *
Array
(
[0] => Array
(
[Priority] => Array
(
[id] => 1
[description] => 1 (urgent)
)
)
[1] => Array
(
[Priority] => Array
(
[id] => 1
[description] => 2
)
)
[2] => Array
(
[Priority] => Array
(
[id] => 1
[description] => 3
)
)
[3] => Array
(
[Priority] => Array
(
[id] => 1
[description] => 4
)
)
[4] => Array
(
[Priority] => Array
(
[id] => 1
[description] => 5
)
)
)
已经尝试过
- 将 Priority 重命名为 PriorityLevel 以防 Priority 是 CakePHP 中的保留字。
请参阅下面的相关代码:
控制器代码
$priorities = $this->Ticket->Priority->find('list', array('fields' => array('Priority.id', 'Priority.description'),'order' => 'Priority.description'));
型号代码
class Ticket extends AppModel {
public $name = 'Ticket';
public $belongsTo = array('Affect', 'Priority', 'User', 'Status');
public $validate = array(
'priority_id' => array(
'rule' => 'notEmpty',
'message' => 'Please assign a priority to this ticket'
)
);
}
class Priority extends AppModel {
public $name = 'Priority';
}
查看代码
echo $this->Form->input('Ticket.priority_id',
array('type' => 'select',
'empty' => true,
'tabindex' => 2));