【问题标题】:Call to a member function find() on null CakePHP在 null CakePHP 上调用成员函数 find()
【发布时间】:2015-11-19 07:33:00
【问题描述】:

我正在尝试在表名联系人中显示我的所有数据,但它给了我一个错误 Call to a member function find() on null。我不明白这是什么意思。请帮忙!

<?php  
        class ContactsController extends AppController {
            var $name = "Contacts";

            public function index() {       
                $this->set('contacts', $this->Contacts->find('all'));
            }
        }
?>

【问题讨论】:

  • 改写这个。 $this->联系方式->find('all')
  • 我猜你使用的是 cakephp 2 所以我添加了适当的标签

标签: cakephp cakephp-2.0


【解决方案1】:

在您的控制器中。

<?php  
    class ContactsController extends AppController {
        public function index() {
            $this->set('contacts', $this->Contact->find('all'));  // here the change Contacts to Contact.
        }
    }
?>

你的模型。

<?php  
    class Contact extends AppModel {
        var $name = "Contact";
    }
?>

【讨论】:

    【解决方案2】:

    在你的控制器中使用变量 $use 如下

    $use = array ('model_name');
    

    只有这样

    【讨论】:

      【解决方案3】:

      您必须在 controller 的标题部分中使用以下代码

      public $uses = array('Your_Model_Name');  // array('User');
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-08-09
        • 1970-01-01
        • 2020-03-10
        相关资源
        最近更新 更多