__Contruct()错误

来源:5-3 系统变量原生标签

杰克不接客

2017-09-11 06:43

<?php
namespace app\index\controller;

use think\Controller;
use think\Request;

class Index extends Controller
{
    public function __construct(){
        config('before', 'beforeAction');
    }
    public function index(Request $request)
    {
        return $this->fetch();
    }
}

上面的代码,直接跑会报一个‘

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

’的错误,但是删除掉construct函数后就没问题了,请问这个是怎么没一个情况?

写回答 关注

1回答

  • 旅行的石头
    2017-09-14 13:06:53

    你需要添加一行  parent::__construct();

快速入门ThinkPHP 5.0--基础篇

ThinkPHP5已发布多时,想了解ThinkPHP5的新特性吗?老司机带你马上出发~

58761 学习 · 503 问题

查看课程

相似问题