繁体   English   中英

是否可以从可执行的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有几个问题...

Cron 1)您正在使用控制器文件的绝对路径,应该是index.php的绝对路径

Cron 2)如果要使用http地址,则应使用curl -L --silent“ www.example.com”

Cron 3)不是绝对的文档路径

Cron 4)应该为php和index.php使用绝对路径

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

从您的类中创建一个“新的” CodeIgniter对象,然后使用这些功能。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM