久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

調用布爾成員函數是什么意思以及如何修復

What means Call to a member function on boolean and how to fix(調用布爾成員函數是什么意思以及如何修復)
本文介紹了調用布爾成員函數是什么意思以及如何修復的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我是 cakePHP 3 的新手.我創建了一個控制器和模型,我在其中調用了一個函數來從數據庫中獲取所有用戶.但是當我運行下面的代碼時,我會得到以下錯誤在布爾值上調用成員函數 get_all_users()".

I'm new with cakePHP 3. I have created a controller and model where I call a function to get all users from the database. But when I run the code below I will get the following error "Call to a member function get_all_users() on boolean".

這個錯誤是什么意思,我該如何解決?

what does this error means and how can I fix this up?

User.php(模型)

namespace AppModelEntity;
use CakeORMEntity;

class User extends Entity {

    public function get_all_users() {
        // find users and return to controller
        return $this->User->find('all');
    }
}

UsersController.php(控制器)

namespace AppController;
use AppControllerAppController;

class UsersController extends AppController {

    public function index() {
        // get all users from model
        $this->set('users', $this->User->get_all_users());
    }
}

推薦答案

通常在使用控制器的不存在的屬性時會發生此錯誤.

Generally this error happens when a non-existent property of a controller is being used.

與控制器名稱匹配的表不需要是手動加載/設置為屬性,但即使它們最初不存在,嘗試訪問它們會導致調用控制器魔術getter方法,該方法用于延遲加載表類屬于控制器,它在出錯時返回 false,這就是它發生的地方,你將調用一個布爾值的方法.

Tables that do match the controller name do not need to be loaded/set to a property manually, but not even they exist initially, trying to access them causes the controllers magic getter method to be invoked, wich is used for lazy loading the table class that belongs to the controller, and it returns false on error, and that's where it happens, you will be calling a method on a boolean.

https://github.com/cakephp/.../blob/3.0.10/src/Controller/Controller.php#L339

在您的情況下,問題是 User(單數,對于實體)與預期的 Users(復數,對于表)不匹配,因此沒有匹配的表類可以找到.

In your case the problem is that User (singular, for entities) doesn't match the expected Users (plural, for tables), hence no matching table class can be found.

你的自定義方法應該放在一個表類中,UsersTable 類,然后你應該通過

Your custom method should go in a table class instead, the UsersTable class, which you should then access via

$this->Users

您可能想重新閱讀文檔,實體不查詢數據(除非您例如實施延遲加載),它們代表一個數據集!

You may want to reread the docs, entities do not query data (unless you are for example implementing lazy loading), they represent a dataset!

這篇關于調用布爾成員函數是什么意思以及如何修復的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Action View Helper in Zend - Work around?(Zend 中的動作視圖助手 - 解決方法?)
Is this a good way to match URI to class/method in PHP for MVC(這是將 URI 與 PHP 中用于 MVC 的類/方法匹配的好方法嗎)
Where do I save partial (views) in Zend Framework, to be accessible for all Views in my App?(我在哪里保存 Zend Framework 中的部分(視圖),以便我的應用程序中的所有視圖都可以訪問?) - IT屋-程序員軟件開發技術
Having a single entry point to a website. Bad? Good? Non-issue?(有一個網站的單一入口點.壞的?好的?沒問題?)
Is MVC + Service Layer common in zend or PHP?(MVC + 服務層在 Zend 或 PHP 中常見嗎?)
Hello World example in MVC approach to PHP(PHP MVC 方法中的 Hello World 示例)
主站蜘蛛池模板: 亚洲国产aⅴ成人精品无吗 亚洲精品久久久一区二区三区 | 天天艹 | 日日夜夜天天综合 | 久久精品成人 | 亚洲一区二区三区视频 | 久久久噜噜噜www成人网 | 精品国产乱码一区二区三区 | 久久一二| 国产xxx在线观看 | 国产精品一区二区久久 | 在线日韩av电影 | 精品成人av | 成人在线中文字幕 | 精品久久久久久久久久久 | 日韩有码一区 | 中文字幕免费在线 | 日韩亚洲欧美一区 | 91精品国产高清一区二区三区 | 精品国产欧美一区二区三区成人 | 国产高清美女一级a毛片久久w | 人人叉 | 国产免费让你躁在线视频 | 国产精品成人av | 国产精品久久久久久久久久软件 | 午夜精品一区 | 日韩欧美三区 | 在线激情视频 | 日韩欧美久久精品 | 日本久久一区二区三区 | 天天插天天舔 | 午夜爱爱毛片xxxx视频免费看 | 91久久国产综合久久91精品网站 | 欧美成人手机视频 | 日韩精品在线观看免费 | 国产高清视频在线 | 欧美一区二区三区精品 | 久久综合激情 | 亚洲免费视频网站 | 欧美日韩亚洲系列 | 欧美美女爱爱视频 | 国产成人网|