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

Unable to use another controller'method in one controller? #997

Closed
jinmarcus opened this issue Apr 22, 2018 · 1 comment
Closed

Unable to use another controller'method in one controller? #997

jinmarcus opened this issue Apr 22, 2018 · 1 comment

Comments

@jinmarcus
Copy link

Unable to use another controller'method in one controller?

like this:

namespace Common\Controller;
use App\Controllers\Login;

class Common extends \CodeIgniter\Controller {
       $login = new Login();
       $login->test();
}

and wrong

ArgumentCountError
Too few arguments to function CodeIgniter\Controller::__construct(), 0 passed in
@lonnieezell
Copy link
Member

Personally, I'd say what you're doing is bad practice. A controller is specifically meant to control flow through the application from the user's input to returning the response. What you're trying to do is better done in a separate class.

That being said, they're just classes. The error should tell you what to look for. There are arguments in the Controller's constructor that it's expecting. If you look at the Controller class itself, you'll see it expects a Request object, a Response object, and a Logger object, IIRC.

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

2 participants