Call to a member function assign() on null

https://blog.csdn.net/jacko_chan/article/details/54406178

Thinkphp:

在子控制器里面写了一个构造函数,如下

 
  1. //构造函数

  2. public function __construct(){

  3. echo 1;

  4. }

 

结果页面报错了  ---->  Call to a member function assign() on null

Call to a member function assign() on null

 

然后去继承的父类里面一看,原来里面写了一个_initialize()的方法,原来是子类的构造函数覆盖了父类的,所以报错了,所以需要继承一下父类的构造函数:

 

parent::__construct();

 

其实_initialize()是TP封装的方法,和php自带的__construct()方法是差不多一样的,不过有一点区别,那就是_initialize() 它会帮我们自己继承父类的构造函数,而__construct()源生自带的,需要自己去继承父类构造函数Call to a member function assign() on null

--------------------- 本文来自 -JackoChan 的CSDN 博客 ,全文地址请点击:https://blog.csdn.net/jacko_chan/article/details/54406178?utm_source=copy