Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何将参数从cron命令传递到codeigniter函数?_Php_Codeigniter_Cron_Crontab_Cron Task - Fatal编程技术网

Php 如何将参数从cron命令传递到codeigniter函数?

Php 如何将参数从cron命令传递到codeigniter函数?,php,codeigniter,cron,crontab,cron-task,Php,Codeigniter,Cron,Crontab,Cron Task,我正在使用CodeIgniter并运行cron作业中的一个函数 class event extends CI_Controller { public function newEvent() { //some process here using the parameter } } cron命令: * */2 * * * /usr/bin/php /var/www/project/index.php 'event/newEvent/parameter'

我正在使用CodeIgniter并运行cron作业中的一个函数

class event extends CI_Controller {
  public function newEvent()
    {
         //some process here using the parameter
    }

} 
cron命令:

* */2 * * * /usr/bin/php /var/www/project/index.php 'event/newEvent/parameter'
我希望像在cron命令中写入的那样传递参数,并在newEvent函数中使用该参数进行一些处理

要从cron命令接收参数,我应该在函数中编写哪些额外的代码


谢谢

您只需在函数中添加一个参数即可

class event extends CI_Controller {

    public function newEvent($parameter)
    {
        //some process here using the parameter
        echo $parameter;
    }

} 
默认路由引擎将继续处理您的参数并将其传递给您的函数。如果该参数是可选的,请随意将其初始化为默认值

    public function newEvent($parameter = 'default')
    {
        //some process here using the parameter
        echo $parameter;
    }
编辑:在阅读了@dm03514的答案后,似乎是希望用空格而不是斜杠来调用应用程序

cron命令应该是

* */2 * * * /usr/bin/php /var/www/project/index.php event newEvent parameter

只需向函数中添加一个参数即可

class event extends CI_Controller {

    public function newEvent($parameter)
    {
        //some process here using the parameter
        echo $parameter;
    }

} 
默认路由引擎将继续处理您的参数并将其传递给您的函数。如果该参数是可选的,请随意将其初始化为默认值

    public function newEvent($parameter = 'default')
    {
        //some process here using the parameter
        echo $parameter;
    }
编辑:在阅读了@dm03514的答案后,似乎是希望用空格而不是斜杠来调用应用程序

cron命令应该是

* */2 * * * /usr/bin/php /var/www/project/index.php event newEvent parameter
CI如何在文档中从命令行执行命令

php index.php event newEvent参数

CI如何在文档中从命令行执行命令


php index.php event newEvent参数

我已经试过了,它对我有效

* */2 * * * /usr/bin/curl http://domain.com/index.php/event/newEvent/parameter

我试过这个,它对我有效

* */2 * * * /usr/bin/curl http://domain.com/index.php/event/newEvent/parameter

你在那件事上比我快你在那件事上比我快这是另一个很好的方法。它是开箱即用还是您必须向方法中添加参数?我已在方法中添加了一个参数。它确实有效,但不推荐使用codeigniter提供的cli方法。运行curl或wget可以使您的函数公开可见。这是另一个很好的方法。它是开箱即用还是您必须向方法中添加参数?我已在方法中添加了一个参数。它确实有效,但不推荐使用codeigniter提供的cli方法。运行curl或wget会使函数公开可见。