【发布时间】:2014-09-16 07:19:14
【问题描述】:
我在简单保存时收到“调用非对象上的成员函数 create()”错误,其中相同的代码在另一个项目中工作。名称对于模型是正确的,并且该名称的表存在于名为 trequestamends 的 mysql 中。 我确定这是一个简单的错误,但我找不到问题,我检查了文档
http://book.cakephp.org/2.0/en/models/saving-your-data.html http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html
public function trequestAmend($id=0) {
...
if ($this->request->is('post')) {
$this->Trequestamend->create();
if ($this->Trequestamend->save($this->request->data)) {
$this->Session->setFlash(__('Your Tutor Requested Amended data has been saved.'));
// return $this->redirect(array('action' => 'displayall'));
}
$this->Session->setFlash(__('Unable to add your post.'));
}
view
echo $this->Form->create('Trequestamend');
echo $this->Form->input($lessonId, array('type' => 'hidden'));
echo $this->Form->input($tutorId, array('type' => 'hidden'));
echo $this->Form->input($stId, array('type' => 'hidden'));
echo "<b>Change times to </b>" . $this->Form->input('start_time', array( 'type' => 'time', 'selected' => '13:00:00'));
echo $this->Form->input('end_time', array( 'type' => 'time', 'selected' => array('hour' => '1','minute' => '30','meridian' => 'pm')));
echo $this->Form->input('lesson_date', array( 'type' => 'date', 'dateFormat' => 'DMY', 'minYear' => date('Y'), 'maxYear' => date('Y')+1));
echo $this->Form->input('reason', array('label' => 'Reasons for Lesson Amendment', 'style' => 'width: 300px; height: 50px;'));
echo $this->Form->end('Save Post');
【问题讨论】:
-
你的控制器名称是什么
-
函数同名,加t加复数
-
您的控制器名称是“TrequestAmendsController”??
标签: cakephp