是否可以从可执行的 PHP 文件调用 Codeigniter 类函数


Is it possible to call a Codeigniter class function from an executable PHP file?

是否可以从可执行的PHP文件调用Codeigniter类函数?我有一个控制器类,我想从可执行的 PHP 文件中调用该类的函数。

为什么?因为我的应用程序适用于 cronjobs。当我从 GUI 创建 cronjob 时,会创建一个新的 php 文件并使用配置进行设置以调用控制器函数。

我该怎么做?

编辑:

我试过这个例子,但它不起作用。创建的 cronjobs 是(要测试的组合):

* * * * * /usr/bin/php /home/myweb/public_html/CI/application/controllers/tools message
* * * * * /usr/bin/php http://www.myweb.com/CI/site/index.php/tools/message
* * * * * /usr/bin/php index.php tools message
* * * * * php index.php tools message

但它们不起作用

编辑:

在Ben的回答之后,我试过了(我有一个站点文件夹):

* * * * * /usr/bin/php /home/myweb/public_html/CI/index.php tools message
* * * * * /usr/bin/php /home/myweb/public_html/CI/site/index.php tools message

我收到下一个日志错误:

ERROR - 2013-01-30 05:52:01 --> Severity: Notice  --> Undefined index:  REMOTE_ADDR /home/myweb/public_html/CI/system/core/Input.php 351
ERROR - 2013-01-30 05:52:01 --> Severity: Warning  --> Cannot modify header information - headers already sent by (output started at /home/myweb/public_html/CI/system/core/Exceptions.php:185) /home/myweb/public_html/CI/system/libraries/Session.php 675
ERROR - 2013-01-30 05:52:01 --> Severity: Warning  --> Cannot modify header information - headers already sent by (output started at /home/myweb/public_html/CI/system/core/Exceptions.php:185) /home/myweb/public_html/CI/system/helpers/url_helper.php 542

[已解决]我已经用卷曲解决了它:

* * * * * /usr/bin/curl http://www.myweb.com/CI/site/index.php/tools/message

是的,这是可能的。直接来自 CI 文档...

http://ellislab.com/codeigniter/user-guide/general/cli.html

从您的问题更新中编辑...

你的cron有几个问题...

克龙 1)你正在使用控制器文件的绝对路径,应该是索引的绝对路径.php

克龙 2)如果你想使用 http 地址,那么你应该使用 curl -L --silent "www.example.com"

克龙 3)不是绝对文档路径

Cron 4) 应该同时使用 php 和索引的绝对路径.php

是的,你可以。 只需确保所有正确的文件都包含在所需的上下文中即可。

从类创建一个"新"CodeIgniter 对象,然后使用这些函数。