Welcome Guest, Not a member yet? Register   Sign In
Command Line Routing
#1

[eluser]Belou[/eluser]
Hi everybody,
First my mother language is French so excuse me for my bad english.

I have a problem with CI and his routing system, I execute php in command line with CI but I have some controllers and i want to execute one of them without modify /config/routes.php at each controller's change .
How can I execute the different controllers without modify this file.
Thanks for your help
Belou
#2

[eluser]xwero[/eluser]
CI is a web framework which means the routing is based on http headers so you would have to make your own router if you need to run controllers in the command line.
#3

[eluser]Belou[/eluser]
Ok thanks , I thought it has a way to use the routes.php but no , so thanks for your fast reply
#4

[eluser]xwero[/eluser]
If you use it on the same server it's best you do something like
php ci.php controller method
Which would be the equivalent of index.php/controller/method
#5

[eluser]Unknown[/eluser]
Try this to mimic simple HTTP GET requests.
Create cli.php in the same directory as index.php and copy this code into cli.php
Code:
<?php

if ($_SERVER['SCRIPT_FILENAME'] != 'cli.php') {
    echo 'no web access';
    exit;
}

ini_set('max_execution_time','0');
set_time_limit(0);

$_SERVER['PATH_INFO']    = $argv[1];
$_SERVER['QUERY_STRING'] = $argv[1];

require('index.php');

/**
* Usage: $ php cli.php controller/action[/parameters]
*/
#6

[eluser]Belou[/eluser]
Thanks for your help but i did a file who modify routes.php with sed (unix-command) because the OS is FreeBSD and then this file execute the index.php with the good route.
Code:
exec("sed -i.bak 's/\".*\";/\"controllers_name\";/1' ./system/application/config/routes.php",$sortie);
        $argv=$_SERVER['argv'];
        $argc=$_SERVER['argc'];
        $str='';
        for($i=1;$i<$argc;$i++)
            $str=$str.' '.$argv[$i];
passthru("php index.php".$str,$s);    
exit($s);




Theme © iAndrew 2016 - Forum software by © MyBB