Codeigniter4: Bug: cannot call constructor on controller.

Created on 21 Jun 2020  路  4Comments  路  Source: codeigniter4/CodeIgniter4

I'm trying to call a parent constructor on my controller but it doesn't seem to work. I followed what the documentation tells. Here is my code:

Screenshot_2020-06-22 Error

I'm not sure if it's just me or there something wrong with my PHP version I'm working on.

And this is the error message:
Screenshot_2020-06-22 Error(1)

Context

  • OS: Windows 10 Pro
  • WAMP Local Server
  • PHP version 7.3.12
bug

Most helpful comment

Support questions should be asked over at the forum. However, since you thought it was a bug I'll give you a quick overview.

Assign anything you need available with the BaseController constructor. And that's pretty much it. If you need to do something in a controller that extends BaseController, then you should call parent::__construct(), but only after you've created a constructor in BaseController.

Where did you see that in the docs? We likely need to modify something there.

All 4 comments

BaseController does not define a constructor of its own. Therefore there's no explicit parent constructor to call, and you get such an error.

What do I need to do in order to call the parent constructor in my controller. I want to declare variables accessible to all of the functions inside the controller. Sorry I'm just new to CodeIgniter 4.

Thanks for the explanation.

Support questions should be asked over at the forum. However, since you thought it was a bug I'll give you a quick overview.

Assign anything you need available with the BaseController constructor. And that's pretty much it. If you need to do something in a controller that extends BaseController, then you should call parent::__construct(), but only after you've created a constructor in BaseController.

Where did you see that in the docs? We likely need to modify something there.

I'm so sorry I've been reading the CI user guide from a different website, I realized it just now. My problem is solved now thank you. It's just I'm having a bit of a hard time transitioning from CI3 to CI4 and couldn't find much answers related to my problem from the internet. I'll be closing this now. My bad.

This was the user guide I'm talking about:
http://pneskin2.nekoget.com/codeigniter/4/user_guide/general/controllers.html

Was this page helpful?
0 / 5 - 0 ratings