Too few arguments to function App\Controllers\Parsys::__construct(), 0 passed in

549 views Asked by At

First I code without use RequestInterface and runwell, but I when I applicate the RequestInterface from the docs here: https://codeigniter4.github.io/userguide/incoming/incomingrequest.html I got this error, What happen with my code?

<?php namespace App\Controllers;
use CodeIgniter\HTTP\RequestInterface;

class Parsys extends BaseController {
    protected $request;

    public function __construct(RequestInterface $request) {
        $this->request = $request;
    }

    public function index() {
        $data = [
            'title' => "Parameter System",
        ];
        return view("backend/parsys_frm", $data);
    }

    public function getList() {
        $frm = $request->getGet('frm');
        $q = $this->request->getGet('q');
        $order_by = $this->request->getGet('order_by');
        $page = $this->request->getGet('page');
        $limit = $this->request->getGet('limit');
        $limit = @$limit == 0 ? 10 : $limit;

        $this->queryList($total, $current, $page, $limit, $q, [1 => 1]);

        $data = $current->result_array();
        header('Content-Type: application/json');
        echo json_encode(compact(['total', 'page', 'limit', 'data', 'q']));
    }

I use ubuntu 20.04, lampp PHP 7.4

1

There are 1 answers

0
marcogmonteiro On

Instead of using the __construct magic method use the built in init method.

public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
{
    parent::initController($request, $response, $logger);
}