我正在处理一个奇怪的问题。我有Config
模型,以及这些关联:
var $belongsTo = array(
'Language' => array(
'className' => 'Language',
'foreignKey' => 'default_language',
'conditions' => '',
'fields' => '',
'order' => ''
),
'Webmaster' => array(
'className' => 'User',
'foreignKey' => 'webmaster',
'conditions' => '',
'fields' => '',
'order' => ''
),
'Group' => array(
'className' => 'Group',
'foreignKey' => 'default_group',
'conditions' => '',
'fields' => '',
'order' => ''
),
);
在我ConfigsController
的edit()
行动中:
function edit($id = null) {
if (!$id && empty($this->data)) {
$this->Session->setFlash(__('Invalid config', true));
$this->redirect(array('action' => 'index'));
}
if (!empty($this->data)) {
if ($this->Config->save($this->data)) {
$this->Session->setFlash(__('The config has been saved', true));
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The config could not be saved. Please, try again.', true));
}
}
if (empty($this->data)) {
$this->data = $this->Config->read(null, $id);
}
$languages = $this->Config->Language->find('list');
$webmasters = $this->Config->Webmaster->find('list');
$groups = $this->Config->Group->find('list');
$this->set(compact('languages', 'groups', 'webmasters'));
}
在我edit.ctp
看来,我有:
echo $this->Form->input('Language');
echo $this->Form->input('Webmaster');
echo $this->Form->input('Group');
现在,问题出现了:该组已正确选择,但其他两个(网站管理员和语言)在第一个选项上被重置,没有 selected
属性,并且作为“奖励”,语言选择显示此错误:Notice (8): Uninitialized string offset: 0 [CORE/cake/libs/view/helper.php, line 859]
我挣扎了将近 2 个小时,找不到这个奇怪问题的问题。请你帮助我好吗?谢谢!
编辑
这是调试器显示的内容:
Helper::__selectedArray() - CORE/cake/libs/view/helper.php, line 859
Helper::value() - CORE/cake/libs/view/helper.php,第 712 行 Helper::_initInputField() - CORE/cake/libs/view/helper.php,第 753 行 FormHelper::_initInputField() - CORE /cake/libs/view/helpers/form.php,第 2182 行 FormHelper::select() - CORE/cake/libs/view/helpers/form.php,第 1438 行 FormHelper::input() - CORE/cake/libs /view/helpers/form.php,第 882 行包括 - APP/views/configs/edit.ctp,第 10 行 View::_render() - CORE/cake/libs/view/view.php,第 723 行 View::render () - CORE/cake/libs/view/view.php,第 419 行 Controller::render() - CORE/cake/libs/controller/controller.php,第 913 行 Dispatcher::_invoke() - CORE/cake/dispatcher .php,第 207 行 Dispatcher::dispatch() - CORE/cake/dispatcher.php,第 171 行 [main] - APP/webroot/index.php,第 83 行
在“代码”选项卡中:
if (!empty($data)) {
foreach ($data as $var) {
$array[$var[$key]] = $var[$key];