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

相关文章:

  • 2020-04-13
  • 2021-10-19
  • 2018-07-18
  • 2021-09-14
  • 2019-07-20
  • 2021-09-30
  • 2021-10-19
猜你喜欢
  • 2018-06-05
  • 2021-09-11
  • 2021-09-11
  • 2021-11-15
  • 2019-09-18
  • 2021-11-05
  • 2021-09-08
  • 2019-09-20
相关资源
相似解决方案