Skip to content

Controller Call to a member function getPost() on null  #2823

Description

@afraidjpg

Version: 4.0.2

<?php

namespace App\Controllers;

use CodeIgniter\API\ResponseTrait;
use CodeIgniter\HTTP\Request;
use CodeIgniter\HTTP\RequestInterface;
use Services\WxConfig;

class Message extends BaseController
{
//    use ResponseTrait;

    public function __construct()
    {
        $user_email = $this->request->getPost('user_email');
        $user_phone = $this->request->getPost('user_phone');
    }
}

I just use this and run my code, then got the error report:

Call to a member function getPost() on null

according to the guide, I extend the BaseController ( I saw that BaseController extend Controller)
I try to add parent::__construct();, but didn't work, I saw the code in BaseController, So did I must run parent::initController(....); ? If it is like this, it means I must code these in every controller, and fill in \CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger ?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions