Cakephp 1.3编辑Acton未填充字段
我的编辑操作有问题,我不确定我的问题是什么,但我的字段没有填充。在我的模型中,我有一个基于id检索3条记录的函数,我在控制器中调用该函数,该函数反过来应该填充视图中的数据。我尝试过调试,但没有成功。我尝试过使用die(debug($this->data));但是,当我运行脚本时,下一页将加载而不是显示$this->data中的内容,这对我来说很奇怪!话虽如此,这就是我得到的。任何意见都将不胜感激!谢谢 模型 控制器Cakephp 1.3编辑Acton未填充字段,php,cakephp,Php,Cakephp,我的编辑操作有问题,我不确定我的问题是什么,但我的字段没有填充。在我的模型中,我有一个基于id检索3条记录的函数,我在控制器中调用该函数,该函数反过来应该填充视图中的数据。我尝试过调试,但没有成功。我尝试过使用die(debug($this->data));但是,当我运行脚本时,下一页将加载而不是显示$this->data中的内容,这对我来说很奇怪!话虽如此,这就是我得到的。任何意见都将不胜感激!谢谢 模型 控制器 public function edit($id = null) { i
public function edit($id = null) {
if (!empty($this->data)) {
die(debug($this->data));
$this->Declination->create();
$this->data = $this->Declination->declinationsForPolicyId($id);
if ($this->Declination->saveAll($this->data['Declination'])) {
$this->Session->setFlash(__('Declinations saved.', true));
$this->redirect(array(
'controller' => 'policies',
'action' => 'view',
$id
));
} else {
$this->Session->setFlash(__('Declinations failed to save.', true));
}
}
$reasons = $this->Declination->Reason->find('list');
$contactTypes = $this->Declination->ContactType->find('list');
$this->set(compact('id', 'reasons', 'contactTypes'));
}
public function edit($id = null) {
if (empty($this->data)) {
$this->data = $this->Declination->declinationsForPolicyId($id);
} else {
// some code
$this->Session->setFlash(__('Declinations failed to save.', true));
}
}
看法
赤纬
当数据不为空时,您正在检索信息,但当数据为空时(第一次加载页面时),您只需填写id、原因、联系人类型
public function edit($id = null) {
if (!empty($this->data)) {
//everything you posted
} else {
$this->request->data = $this->Declination->declinationsForPolicyId($id);
}
}
$reasons = $this->Declination->Reason->find('list');
$contactTypes = $this->Declination->ContactType->find('list');
$this->set(compact('id', 'reasons', 'contactTypes'));
}我解决了我的问题。在整个申请过程中,我做了一些修改。我首先通过编辑html链接传入策略id。之后,我的功能似乎正常工作,因为id被设置为策略id。此外,我对我的编辑功能做了轻微的更改。您可以看到下面的更改 控制器
public function edit($id = null) {
if (!empty($this->data)) {
die(debug($this->data));
$this->Declination->create();
$this->data = $this->Declination->declinationsForPolicyId($id);
if ($this->Declination->saveAll($this->data['Declination'])) {
$this->Session->setFlash(__('Declinations saved.', true));
$this->redirect(array(
'controller' => 'policies',
'action' => 'view',
$id
));
} else {
$this->Session->setFlash(__('Declinations failed to save.', true));
}
}
$reasons = $this->Declination->Reason->find('list');
$contactTypes = $this->Declination->ContactType->find('list');
$this->set(compact('id', 'reasons', 'contactTypes'));
}
public function edit($id = null) {
if (empty($this->data)) {
$this->data = $this->Declination->declinationsForPolicyId($id);
} else {
// some code
$this->Session->setFlash(__('Declinations failed to save.', true));
}
}