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

調(diào)用布爾成員函數(shù)是什么意思以及如何修復(fù)

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

問題描述

我是 cakePHP 3 的新手.我創(chuàng)建了一個控制器和模型,我在其中調(diào)用了一個函數(shù)來從數(shù)據(jù)庫中獲取所有用戶.但是當(dāng)我運行下面的代碼時,我會得到以下錯誤在布爾值上調(diào)用成員函數(shù) 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());
    }
}

推薦答案

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

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

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

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(單數(shù),對于實體)與預(yù)期的 Users(復(fù)數(shù),對于表)不匹配,因此沒有匹配的表類可以找到.

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.

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

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

$this->Users

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

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

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

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

相關(guān)文檔推薦

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 中的部分(視圖),以便我的應(yīng)用程序中的所有視圖都可以訪問?) - IT屋-程序員軟件開發(fā)技術(shù)
Having a single entry point to a website. Bad? Good? Non-issue?(有一個網(wǎng)站的單一入口點.壞的?好的?沒問題?)
Is MVC + Service Layer common in zend or PHP?(MVC + 服務(wù)層在 Zend 或 PHP 中常見嗎?)
Hello World example in MVC approach to PHP(PHP MVC 方法中的 Hello World 示例)
主站蜘蛛池模板: 欧美日一区| 国产高清无av久久 | 亚洲精品成人 | 日韩二区| 欧美一区二区三区在线视频 | 99热精品久久 | 亚洲欧美国产精品久久 | 黄色av网站在线观看 | 久久一区二区三区四区 | 二区三区视频 | 国产精品久久久久久久久久 | 亚洲综合首页 | 久久五月婷| 成人午夜电影在线观看 | 一区二区三区视频在线观看 | 精品一区二区三区免费视频 | 我想看一级黄色毛片 | www国产成人免费观看视频 | 成人免费大片黄在线播放 | 精品成人免费视频 | 国产精品国产精品国产专区不蜜 | 日韩视频中文字幕 | 羞羞免费网站 | 搞黄网站在线观看 | 久久精品一区二区视频 | 国产亚洲精品久久久久动 | 天天干,夜夜操 | 中文字幕一级 | 成人黄色电影在线播放 | 国产精品久久久久久久久污网站 | 色婷婷一区二区三区四区 | 一区二区国产在线观看 | 日韩欧美二区 | 亚洲三区在线观看 | 国产一区三区在线 | 亚洲成人av一区二区 | 国产成人综合网 | 精品www| 久草网站 | 国外激情av | 亚州春色|