使用PHP&;通过命令行接口的代码点火器


Using PHP & Codeigniter via Command Line Interface

我有以下从命令行运行的函数,第一个参数总是一个整数,例如(11),第二个参数总是字符串"acmeinc"

当我通过CLI运行代码时,它会输出:

Number of arguments: 2

然而,我似乎无法在同一函数中将$order_id变量传递给$this->json_path变量——就好像$order_id是作为空值"传递的一样——这能说明为什么会发生这种情况吗?

public function execute($order_id, $merchant)
{   
    $numargs = func_num_args();
    echo "Number of arguments: $numargs'n";
    print_r($numargs[0]);
    print_r($numargs[1]);
    $this->_casperjs_path = 'casperjs';
    $this->script_path = '"/srv/mysite.com/application/casperjs/'. $merchant .'.js"';
    $this->json_path = '"/srv/mysite.com/application/casperjs/orders/'. $merchant .'-'. $order_id .'.txt"';             
    $path = ( $this->_phantomjs_path != '' ? 'PHANTOMJS_EXECUTABLE=' . $this->_phantomjs_path . ' ' : '' ) . $this->_casperjs_path . ' ' . $this->script_path . ' ' . $this->json_path; 
    die($this->json_path); // '"/srv/mysite.com/application/casperjs/orders/acmeinc-.txt"'  
    $return_value = exec( $path, $output = array());
    return $return_value;
}

我希望die()输出如下文件:

'"/srv/mysite.com/application/casperjs/orders/acmeinc-1.txt"'

相反,order_id变量似乎没有传递(或者以某种方式被设置为空变量,如下所示:

'"/srv/mysite.com/application/casperjs/orders/acmeinc-.txt"'

有人能解释为什么会发生这种事吗?

怀疑它…它是通过另一个函数传递的,并默认为一个空变量。。doh!