错误:调用cakepp中非对象的成员函数create(),即使模型的名称已经定义


Error: Call to a member function create() on a non-object in cakephp even thought the name of the model has been defined

错误:调用cakepp中非对象的成员函数create()。我已经在我的控制器页面中定义了所有这些。

联系人控制器:

<?php
 public $helpers = array('Html', 'Form');
 public $components = array('RequestHandler');
 public $uses = array("Contact");
 public function index(){
  if ($this->RequestHandler->isPost()) {
    $this->Contact->set($this->data);
    //validates here
  }
?>

指数.ctp

<?php
//form
echo $form->create("Contact");
echo $form->inputs();
echo $form->end('Send');
?>

但我还是犯了致命的错误吗。需要帮助,谢谢。

使用$this->Form->create()而不是$form->create()

必须在助手对象之前使用$this

您的index.php代码应该如下所示:

<?php
//form
echo $this->Form->create("Contact");
echo $this->Form->inputs();
echo $this->Form->end('Send');
?>

检查好您的控制器类。您是重新定义了AppController::render()还是在子类中重新实现了它?您这样做可能是为了指定应用程序的布局。我也犯了同样的错误。我发现进入render方法的$view参数(即要渲染的视图的名称)为null,因为我覆盖了render方法。如果您没有覆盖render(),请检查您可能设置了控制器$view属性的任何位置。