Cakephp 无法保存新记录,因为找不到模型

Cakephp 无法保存新记录,因为找不到模型,cakephp,Cakephp,我在一个简单的保存中收到一个“对非对象调用成员函数create()”错误,其中相同的代码在另一个项目中工作。这些名称对于模型是正确的,并且该名称的表存在于mysql中,称为TrequeStaments。 我相信这是一个简单的错误,但我找不到问题,我检查了文档 公共函数trequestamind($id=0){ ... 如果($this->request->is('post')){ $this->Trequestamend->create(); 如果($this->trequestamind-

我在一个简单的保存中收到一个“对非对象调用成员函数create()”错误,其中相同的代码在另一个项目中工作。这些名称对于模型是正确的,并且该名称的表存在于mysql中,称为TrequeStaments。 我相信这是一个简单的错误,但我找不到问题,我检查了文档

公共函数trequestamind($id=0){
...
如果($this->request->is('post')){
$this->Trequestamend->create();
如果($this->trequestamind->save($this->request->data)){
$this->Session->setFlash(_u(“您的导师要求的修改数据已保存”);
//返回$this->redirect(数组('action'=>'displayall');
}
$this->Session->setFlash(_u('无法添加您的帖子');
}
看法
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');
回显“将时间更改为”。$this->Form->input('start_time',数组('type'=>'time','selected'=>'13:00:00');
echo$this->Form->input('end_time',数组('type'=>'time','selected'=>数组('hour'=>'1','minute'=>'30','meridian'=>'pm'));
echo$this->Form->input('lesson_date',数组('type'=>'date','dateFormat'=>'DMY','minYear'=>date('Y'),'maxYear'=>date('Y')+1));
echo$this->Form->input('reason',array('label'=>'课程修改原因','style'=>'宽度:300px;高度:50px;');
echo$this->Form->end('savepost');

我认为问题在于cakephp中的名称约定,您应该将表名从“trequestaminds”更改为“trequest\u amends”,模型名为“trequestamind”,然后您可以通过$this->trequestamind->create()调用create方法;
希望它能起作用!

你的控制器名是什么?你的控制器名是“TrequestAmendsController”?好的,它能起作用。我按照你说的那样命名,没有出现错误。隐藏字段由于某种原因无法保存。我会再次检查文档
 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');