您好我想使用cakephp在同一列中插入多个复选框值,但我有错误“试图获取非对象的属性[APP \ Model \ Task.php,第34行]”,即模型
if($this->request->data['Task']['Feel']!=0)
{
$this->data['Task']['Feel'] = implode(',', $this->data['Task']['Feel']);
}
我的观点
<?php
echo $this->Html->css('style');
echo $this->Form->create('task');
?>
<table align= "center">
<div class="checkbox">
<tr>
<td>Name 1</td>
<td>
<?php
$list = array('1' => 'Happy', '2' => 'Laugh', '3' => 'Sad', '4' => 'Angry','5'=>'Cry');
echo $this->Form->input('Feel',array('label' => false,'options' => $list,'multiple'=>'checkbox'));
?>
</td>
</tr>
<tr>
<td>Name 2</td>
<td>
<?php
$list = array('6' => 'Happy', '7' => 'Laugh', '8' => 'Sad', '9' => 'Angry','10'=>'Cry');
echo $this->Form->input('Feel',array('label' => false,'options' => $list,'multiple'=>'checkbox'));
?>
</td>
</tr>
</div>
</table>
<?php
echo $this->Form->input('id', array('type' => 'hidden'));
echo $this->Form->end('Submit');
?>
我的模特
class Task extends AppModel
{
function beforeValidate()
{
if($this->request->data['Task']['Feel']!=0)
{
$this->data['Task']['Feel'] = implode(',', $this->data['Task']['Feel']);
}
}
}
我的控制器
class TaskController extends AppController
{
public $uses = array();
public $helpers = array('Html','Form');
public $components =array('Flash');
public function task($id=null)
{
$this->Task->create();
if ($this->Task->save($this->request->data))
{
$this->Flash->success(__('Your task has been saved.'));
return $this->redirect(array('action' => 'task'));
}else
{
$this->Flash->error(__('Unable to add the task.'));
}
}
}
如何删除此错误以及如何解决? 请任何人帮帮我....
答案 0 :(得分:0)
echo $this->Form->create('task');
这应该是
echo $this->Form->create('Task');
答案 1 :(得分:0)
两个问题:
echo $this->Form->create('task');
应该是:
echo $this->Form->create('Task');
和
if($this->request->data['Task']['Feel']!=0)
应该是:
if($this->data['Task']['Feel']!=0)
甚至更好:
if($this->data['Task']['Feel'])