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

Bug: cannot call constructor on controller. #3145

Closed
zenabus opened this issue Jun 21, 2020 · 4 comments
Closed

Bug: cannot call constructor on controller. #3145

zenabus opened this issue Jun 21, 2020 · 4 comments
Labels
bug Verified issues on the current code behavior or pull requests that will fix them

Comments

@zenabus
Copy link

zenabus commented Jun 21, 2020

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
@zenabus zenabus added the bug Verified issues on the current code behavior or pull requests that will fix them label Jun 21, 2020
@paulbalandan
Copy link
Member

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

@zenabus
Copy link
Author

zenabus commented Jun 21, 2020

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.

@lonnieezell
Copy link
Member

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.

@zenabus
Copy link
Author

zenabus commented Jun 22, 2020

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

@zenabus zenabus closed this as completed Jun 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them
Projects
None yet
Development

No branches or pull requests

3 participants