我面臨着一個奇怪的問題,同時創造CakePHP中2.1CakePHP的模型錯誤
錯誤編輯功能genreated: 非法偏移類型[CORE \蛋糕\型號\ Model.php,行2689]
我的編輯.ctp文件
<?php echo $this->Form->create('Task');?>
<fieldset>
<legend>Edit Task</legend>
<?php
echo $this->Form->hidden('id');
echo $this->Form->input('title');
echo $this->Form->input('done');
?>
</fieldset>
<?php echo $this->Form->end('Save');?>
型號:Task.php
<?php
class Task extends AppModel {
var $name = 'Task';
}
?>
控制器:TasksController.php
<?php
class TasksController extends AppController {
var $name = 'Tasks';
var $helpers = array('Html', 'Form');
function index() {
$this->set('tasks', $this->Task->find('all'));
}
function add() {
if (!empty($this->data)) {
$this->Task->create();
if($this->Task->save($this->data)){
$this->Session->setFlash('The Task has been saved');
$this->redirect(array('action'=>'index'),null,true);
}else{
$this->Session->setFlash('Task not saved.Try again.');
}
}
}
function edit($id = null) {
if (!$id) {
$this->Session->setFlash('Invalid Task');
$this->redirect(array('action' => 'index'), null, true);
}
if (empty($this->data)) {
$this->data = $this->Task->find(array('id' => $id));
} else {
if ($this->Task->save($this->data)) {
$this->Session->setFlash('The Task has been saved');
$this->redirect(array('action' => 'index'), null, true);
} else {
$this->Session->setFlash('The Task could not be saved.Please, try again.');
}
}
}
}
?>
您可以發佈您的相關型號和控制器代碼嗎? 'edit.ctp'本身並不能真正幫助確定錯誤。 – mensch 2012-04-17 08:58:56
和你的控制器代碼?最好用代碼編輯你的問題,這樣你就可以正確格式化它,而不是將它作爲評論發佈。 – mensch 2012-04-17 09:04:00