Welcome Guest, Not a member yet? Register   Sign In
CLI Only Shows Default Controller
#1

[eluser]Jonah Dahlquist[/eluser]
Hello, world!

I'm working with CodeIgniter for the first time, and I've run into a problem with using it via CLI. I have a controller at application/controllers/datasource.php, and when I try to run:

Code:
$ php index.php datasource

It outputs the home page. Opening other controllers in the browser works just fine, but I can't seem to load any controllers from the CLI. I tried changing the $config['uri_protocol'] variable, but nothing affected it. What might the problem be?

Thanks!

Edit: I've found a couple of other places where other people have had the same problem, but no solution:

http://ellislab.com/forums/viewthread/201026/
http://stackoverflow.com/questions/76773...ted-result

I tried disabling all autoloads, but it still tried to load the default controller. It would appear that the routing isn't getting the information it needs.
#2

[eluser]bientek[/eluser]
I have a similar problem. Are you also using cron? For me, I get the default controller when using cron, but it works fine when using the CLI directly.
#3

[eluser]CroNiX[/eluser]
try providing the full path to php

/path/to/php /path/to/ci/index.php controller method params
#4

[eluser]bientek[/eluser]
Thanks. I have tried /usr/bin/php and also /usr/local/bin/php (mentioned in the thread I linked to) with the same undesired result.
#5

[eluser]CroNiX[/eluser]
I still just use the old "cronjob bootstrapper" method, which has worked for me since version 1.7 and still does. Unfortunately when they moved the wiki to github it seems to have gotten lost, but here is Jons article about it...
http://jonathonhill.net/codeigniter/cron/

One thing that is helpful is it allows you to set server variables, such as the http_host, which can be important if you have settings in your app that rely on them, since they won't be available via a CLI request since it didn't come from HTTP. I don't think CI's way does that.

That might also be part of your problem (relying on SERVER vars in your code which aren't present during a CLI request)
#6

[eluser]Jonah Dahlquist[/eluser]
Thank you CroNiX, I'll check that article. I tried using the full path, but it did not fix it. I've decided to run the CLI interface separately from the rest of the application, so I'll just copy the models over that I need to a new application. I'll let you know if it works.
#7

[eluser]bientek[/eluser]
[quote author="CroNiX" date="1346195507"]try providing the full path to php

/path/to/php /path/to/ci/index.php controller method params
[/quote]
This was close to the solution for me. Environment variables had to be set up. Jonah, if you still want to use CLI, I think the same may apply to you regardless of whether you use cron or not.
#8

[eluser]Jonah Dahlquist[/eluser]
Strange, it's working now. I can just call

Code:
$ php index.php datasource

And it works. I wonder what the problem was? I've worked on a lot of things, but I thought it was the same. Maybe I missed something and had a wrong name or something. Thanks a lot.




Theme © iAndrew 2016 - Forum software by © MyBB