从外部脚本访问Codeigniter函数 [英] Access Codeigniter functions from external script

查看:181
本文介绍了从外部脚本访问Codeigniter函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,这里是我的情况:




  • 我有一个完整的应用程序设置与CodeIgniter。

  • 我正在启动后台任务,运行PHP脚本。



我的问题: p>


  • 如何使用CodeIgniter函数(例如 $ this-> db 或<$



hr>

建议:可能是一个解决方法,如在顶部包括index.php;

解决方案

在最近的Codeigniter版本中,您可以从命令行运行标准控制器操作
如果你的任务是某种类型的守护进程,你可以将任务触发器逻辑嵌入你的脚本的长时间运行的部分,然后shell实际工作到CI陆地。


So, here's my situation :

  • I have a complete app set up with CodeIgniter.
  • I'm initiating a background task, running a PHP script.

My question :

  • How could I use CodeIgniter function (e.g. $this->db or $CI->db - doesn't matter) from that external PHP script?

Idea : Could a workaround, like include 'index.php'; at the top of the script do the trick?

解决方案

In recent Codeigniter versions you can run standard controller actions from command line. If your task is some kind of a daemon you can embed the "task trigger" logic in a long running part of your script and shell out for the actual work to CI land.

这篇关于从外部脚本访问Codeigniter函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆