关于“Call to a member function display() on a non-object”的解决方案

最近做一个基于thinkphp框架,调用接口的项目,其中遇到这样一个问题:在公共控制器中使用php的构造函数__construct()函数,然后让各个子控制器进行继承操作,主要是是为了做权限节点控制,部分代码如下:

 1 class CommonController extends Controller{
 2
 3     public function __construct(){
 4
 5
 6         //节点控制设置。
 7         if ( !( $_COOKIE[‘user_id‘] && $_COOKIE[‘mobile‘] && $_COOKIE[‘username‘] ) ){
 8
 9             $this->redirect(‘Login/index‘); //重定向url
10         }
11     }
12 }

报错如下:

解决办法如下:因为红公告控制器是继承Controller的,因为 继承父类时,应带上parent::__construct();

时间: 2024-10-16 18:46:18

关于“Call to a member function display() on a non-object”的解决方案的相关文章

Fatal error: Call to a member function read() on a non

选模版时报错如下:Fatal error: Call to a member function read() on a non-object inC:\wamp\www\DedCms5.7\include\dialog\select_templets.php on line 71或者是/include//templets/default/index.htm Not Found!95%的导致原因是本地测试好了之后上传到服务器的路径问题!解决方法:后台->系统->系统基本设置->核心设置 -

'init':member function definition looks like a ctor(构造函数的缩写)

具体编译的错误提示如下:warning C4183: 'init': member function definition looks like a ctor, but name does not match enclosing classwarning C4183: 'method': member function definition looks like a ctor, but name does not match enclosing classLinking...main.exe -

ECmall错误:Call to a member function get_users_count() on a non-object

问题描述: 在后台添加了一个app报错:Call to a member function get_users_count()Fatal error: Call to a member function get_users_count() on a non-object in \includes\ecapp.base.php on line 问题原因有一下几点: 1.你的APP文件没有对应的Lang文件: 2.你的APP文件和Lang文件如果是UTF编码的,可能是有BOM: 3.你的APP文件和

Fatal error: Call to a member function on a non-object 的2种解决办法

这两天被一个莫名其妙的错误:Fatal error: Call to a member function on a non-object in d://www/htdocs/inc.php 77  搞的是晕头转向的.花了两天的功夫也没找出原因.在网上也没有搜索到解决的办法.无奈之下只好一行一行的比对代码,最后终于发现了错误之处:数据库字段错误! 一开始我根本就没有联想到这方面的原因,只是不断的在代码中找原因.无论怎么找都是没问题的,甚至将函数重写也无济于事.之后查看数据库表的时后发现了问题:原来

static 和 no static Member function学习

以下是做实验的一段代码: #include <iostream> using namespace std; typedef void (*p)(); class Object { public: static void s_fun_1() { cout << "static function 1\n"; } void fun_1() {cout << "no static function 1\n";} }; typedef vo

Call to a member function free_result() on a non-object

1.平时用框架用久了,直接执行原生的sql反而做起来反应迟钝了.今天遇到一个问题,就是直接执行一个添加的sql语句,然后我用了TP框架的M()->query();方法.运行以后,会报Call to a member function free_result() on a non-object这行错误,找了半天也不知道怎么回事,然后找到了 free_result()具体实现方法的地方看了代码,这个方法是释放查询的结果集.然而我执行的是添加操作,也就会报错了.M()->query():是执行查询语

Timer.4 - Using a member function as a handler

In this tutorial we will see how to use a class member function as a callback handler. The program should execute identically to the tutorial program from tutorial Timer.3. #include <iostream> #include <boost/asio.hpp> #include <boost/bind.

Fatal error: Call to a member function getData() on a non-object in /data/php/framework/exts/zii/wid

使用Yii框架的zii.widgets.CListView遇到的错误:zii.widgets.CListView <?php $this->widget('zii.widgets.CListView', array( 'dataProvider' => $order, 'itemView' => '_providerlist', 'emptyText' => '暂无数据', 'itemsTagName'=>'div', 'template'=>'{items}{p

php 写入数据库时Call to a member function bind_param() on a non-object

<?php $servername = "localhost"; $username = "username"; $password = "password"; $dbname = "myDB"; // 创建连接 $conn = new mysqli($servername, $username, $password, $dbname); // 检测连接 if ($conn->connect_error) { di