PHP CI Controller Function Calling from outside framework
I am using CI Controller and all functionality developed within the framework (Test_frame1). Now from a different domain, i like to call the identified features from my CI Framework i.e. test_frame1.
How to make such calls? Can Test_frame1, expose any web services which can be directly c开发者_运维问答alled from external websites? How the web service can be routed to private method calls within my CI Controller? What kind of security aspects to be considered? Any example code and explanation is highly appreciated.
Thank You,
One way to do this is to make your reusable functions in Test_frame1 available as API calls.
Here is a good link but a long read too.
http://net.tutsplus.com/tutorials/php/working-with-restful-services-in-codeigniter-2/
I had some similar issue and I've solved a little bit tricky but it working :)
I have a cms made in codeigniter which generate static files to the main site, it sounds bad but I try to illustrate in other way:
root - cms_folder (codeigniter system)
- images
- js
- assets
- index.html
I want to handle the ajax requests with the codeigniter's controller and at the same time I want to hide the real path of the codeigniter folder. To make this I've made a redirect in the .htaccess file:
RewriteCond %{THE_REQUEST} ^.*ajax_action/(.*) [NC]
RewriteRule ^.*ajax_action/(.*) http://%{HTTP_HOST}/cms_folder/ajaxcall/$1 [NC,P]
And the ajax request I've made look like this:
$.ajax({
'url': '/ajax_action/'+action, // action is the ajaxcall controller's function
'data' : {parameters},
'type': 'POST',
../ other ajax settings ...
});
I know my english is really bad, but I hope I help with this someone at some time :)
精彩评论