Welcome Guest, Not a member yet? Register   Sign In
Issue with routing when running from the CLI
#1

[eluser]Unknown[/eluser]
I'm trying to run a script via the CLI, but am having some issues getting it to route to the proper controller.

Here is my routes.php file:

Code:
$route['default_controller'] = "home";
$route['scaffolding_trigger'] = "scaffolding";

// URI like '/en/about' -> use controller 'about'
$route['^fr/(.+)$'] = "$1";
$route['^en/(.+)$'] = "$1";

// '/en' and '/fr' URIs -> use default controller
$route['^fr$'] = $route['default_controller'];
$route['^en$'] = $route['default_controller'];

The function I'm trying to call is on my non-default controller. To access it via the web, I can use this URL and it works fine: http://localhost/mobile.php/en/mycontroller/myfunction

Two things to note here (not sure if they matter):

1) We are using a non-default main php file of mobile.php instead of index.php

2) We do not have an .htaccess file set up, so we are just using the mobile.php directly in the URL.

Now, when I try to access this same function via the CLI, it is always loading up the default controller:

Code:
php mobile.php en mycontroller myfunction

I have tried this with and without the "en". Any ideas what I'm doing wrong here?
#2

[eluser]bigmac[/eluser]
I see that it has been well over a year since the last post. Has any progress been made?

I am attempting to use the CLI interface as well and am not getting anywhere. The Router simply does not see the command line and thus does not construct the request. Is this partially a PHP configuration issue? (Something I will look into).

Any constructive thought on the issue would be appreciated.
#3

[eluser]CroNiX[/eluser]
Not positive, but it could be that routes are relying on a $_SERVER attribute being set, such as REQUEST_URI or similar, which isn't set when used via the CLI since it's not a web request. Using the full unrouted controller/method/etc should work via the CLI the way the user guide shows.
#4

[eluser]bigmac[/eluser]
Correct - the _SERVER environment is simply missing and not replicated by PHP or CI.

The solution for me was to simply set the config var 'uri_protocol' to 'AUTO' - and the web access continues to function. The User Guide CLI example fails, reliably, if this isn't done this way..

Also found a spot in core/Input.php (line 351) where it attempts to determine the IP address the request is sourced from. Same problem.

Cheers




Theme © iAndrew 2016 - Forum software by © MyBB