Using CI from PHP (rather than URL)

#1
[eluser]nzDavid[/eluser]
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:
http://somedomain/ci/somecontroller/somefunction/someparam

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

hope I have explained the question well enough.

Cheers,
David

#2
[eluser]Twisted1919[/eluser]
Well, curl ?

#3
[eluser]pbreit[/eluser]
Yes, I think Curl might be the best option. For example:
http://us3.php.net/manual/en/curl.examples-basic.php

#4
[eluser]nzDavid[/eluser]
Hi Guys,

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

Cheers,

David

#5
[eluser]fchristant[/eluser]
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.

#6
[eluser]nzDavid[/eluser]
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!

#7
[eluser]fchristant[/eluser]
@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.

#8
[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()

#9
[eluser]fchristant[/eluser]
@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.