Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
afraidjpg opened this issue Apr 14, 2020 · 3 comments
Closed

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

afraidjpg opened this issue Apr 14, 2020 · 3 comments

Comments

@afraidjpg
Copy link

afraidjpg commented Apr 14, 2020

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 ?

@afraidjpg
Copy link
Author

OK, I saw the resource code, I know why it's null now

@Amar-arruf
Copy link

OK, I saw the resource code, I know why it's null now
@afraidjpg
How ? , I have same Error

@kenjis
Copy link
Member

kenjis commented Jun 9, 2022

See

abstract class BaseController extends Controller

class Controller

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants