在null CakePHP上调用成员函数find()

euoag5mw  于 2022-11-11  发布在  PHP
关注(0)|答案(3)|浏览(173)

我试图在一个名为contacts的表中显示我的所有数据,但它给了我一个错误调用一个成员函数find()on null。我不明白这是什么意思。请帮助!

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

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

1u4esq0p1#

在你的控制器里。

<?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";
    }
?>
ngynwnxp

ngynwnxp2#

在控制器中使用变量$use,如下所示

$use = array ('model_name');

只有那个

iyr7buue

iyr7buue3#

你必须在你的controller的头部分使用下面的代码

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

相关问题