Using CI from PHP (rather than URL)

Hi Everyone,

I have used CI in the past and have loved the way it works.

I currently have a legacy code base that I would love to use CI in.
While I am happy (and able to) us CI in the site in a sub directly, I was wondering if it was possible to call CI from a non-ci PHP call?

For example:
Traditional CI call:

Is it possible to call that controller from a non-ci PHP file?

hope I have explained the question well enough.


Well, curl ?

Yes, I think Curl might be the best option. For example:

Hi Guys,

Thanks for the replies.
It was an approach I was thinking of trying.



Curl is perhaps the easiest solution but please note that this is not "calling CI from PHP". It is still using the full web server stack this way. You CAN really use CI directly from the command line without the web stack but it requires a bit of hacking, basically creating a seperate index.php with some modified paths. I use it mostly for cron jobs.

Hi There,

You are on the money, as I was starting to see limitations to what I require if I attempted the "curl" method.

I've seen methods/threads on calling the CI Model by mocking the config in an index.php and am starting to think this may be what I will attempt to work with.

One issue I've seen commented about is that CI will still parse the URL even if you don't want it too.

Once I have some more concret examples of any issues I'll be post again no doubt!

Thanks again for the responses!

@nzDavid. Indeed, all you need to do is to create a copy of index.php and in this copy you manually override some paths that CI normally would calculate. From then on you can use the full CI stack, of course excluding any web server variables.

[eluser]Colin Williams[/eluser]
A controller function should simply piece together the data and views for the client. It's not meant to serve other parts of the application. If you need to abstract functionality, consider whether a helper function is appropriate, or extend the base controller so all sub controller classes have access to the common function via $this->method() or parent::method()

@Colin. Wrong thread? I don't see how your response has anything to do with calling CI from the commandline.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.