Welcome Guest, Not a member yet? Register   Sign In
calling CI's Controller from external script using curl
#1

[eluser]tulipneo[/eluser]
Hi List,
Good Day.
I have a simple problem for which i have been goggling and searching CI forum.
i open my browser and access the links
http://localhost:8080/project/index.php/...s/setInBox
so here i m able to access controller's class method setInBox.thats fine
now i have written an external script and trying to access this through curl but it does not work.the external script is as bellow.
Code:
<?php
$url = "http://localhost:8080/project/index.php/messages/setInBox";
$ch = curl_init($url);
$result = curl_exec($ch);
curl_close ($ch);
?>

Any help or advice or pointer could help me.

Br
Tulip
#2

[eluser]tulipneo[/eluser]
Hi
I dont have still any reply.
i observed in this thread
http://ellislab.com/forums/viewthread/131867/


Code:
$_curl = curl_init ( "http://test.com/index.php/test/example" );
$_result = curl_exec( $_curl );

the bellow woks fine as claimed by the member but why not in my case.
some one pls help.

Br
Tulip
#3

[eluser]tulipneo[/eluser]
Hi List,
pls suggest.
i m stuck.
is this an invalid question to ask.
pls advice.

br
Tulip
#4

[eluser]bubbafoley[/eluser]
use the curl library. it'll make things easier.

http://philsturgeon.co.uk/code/codeigniter-curl
#5

[eluser]danmontgomery[/eluser]
We can't do anything with "does not work", you need to be specific, post error messages, what you've tried, etc
#6

[eluser]tulipneo[/eluser]
Hi thanks for the reply.

inside code igniter controller i have a class called message with method setInBox().

Code:
public setinbox()
{
    _log("i m here");
}

i open browser and type http://localhost:8080/project/index.php/...s/setInBox and press enter and my method is called.

now i try to do the same thing with curl() which does not work.

i can not use CI's curl here bocz i m tring to access Ci's controller from outside the framework.

br
Tulip
#7

[eluser]toopay[/eluser]
Have you try Proxy Library?
#8

[eluser]tulipneo[/eluser]
Hi
Thanks for ur reply.
i think Proxy Library and codeigniter-curl are meant for making calls from CI framework to outside but my situation is that i want to make cals from outside environment to CI framework.

Br
Tulip
#9

[eluser]toopay[/eluser]
Do you mean you want to :
1. Get HTTP response for some url(in this case, the url is pointing to a CI controller function)?....or
2. Uses the class object on some CI controller, from different domain/app?

The first one is possible to do, but i doubt you can do the second!
#10

[eluser]tulipneo[/eluser]
Hi
thanks for ur reply again.
my idea is very simple.
i have a project in CI.
my requirement is tht an out side script should be able to call my controller "message" and method "setinbox".
in order to do that i open my browser and try localhost/index.php/message/setinbox and the method is called.
i want make the same with curl.

so what u have mentioned in step1 is what i need.

my code is as bellow


<?php
$url = "http://localhost:8080/project/index.php/messages/setInBox";
$ch = curl_init($url);
$result = curl_exec($ch);
curl_close ($ch);
?>

so the above external code is trying to call method "setInBox" of controller "message" to my project in CI framework.

now i see the method is not called.

i can confirm that bcoz in first case the log is printed whats given in method name and second case no logs.

br
Tulip




Theme © iAndrew 2016 - Forum software by © MyBB