controller.php Call to a member function fetch() on a non-object问题的解决

前言:


      在做微信测试的时候,突然写了一个类,却怎么也调不出模板出来,我还在疯狂地在fetch()函数边缘测试,,,问题居然在之前之前的一个手贱且操作没有备注

controller.php Call to a member function display() on a non-object

问题如下

controller.php Call to a member function fetch() on a non-object问题的解决

问题解决办法:

我的代码:

class Wechat extends  Controller {

	public function __construct(){
		
	}

    //省略调用下面地函数
    
     public function wechat(){
	 	$res=Session::get("rs");
        if(!Session::has("rs")){
            action("admin/Wechat/getUserDetail");
        }else{
             return $this->fetch('',[
            'user'=>$res,
        ]);
        }
    }

查看了ThinkPHP下的Controller.class.php,,发现报错的位置是: 

controller.php Call to a member function fetch() on a non-object问题的解决

 

到这里,才知道问题的所在了。是我在控制器里面的__construct()方法覆盖掉了父类的构造方法。

controller.php Call to a member function fetch() on a non-object问题的解决

那么现在问题就很好解决了,只需要在我的构造方法里面引入父类的构造方法就可以了。加入后是这样的:

public function __construct(){
		parent::__construct;
	}

当然直接如果不需要的话直接删掉也是可以的。