问答详情
源自:5-3 系统变量原生标签

__Contruct()错误

<?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函数后就没问题了,请问这个是怎么没一个情况?

提问者:杰克不接客 2017-09-11 06:43

个回答

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

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