Welcome Guest, Not a member yet? Register   Sign In
Can't Find Library/Helper/Class in CI
#1

[eluser]jmanpa[/eluser]
What is the preferred way of retrieving the passing the result of a call to a uri to a variable in PHP? I didn't stumble across something within CI, but I may have missed it. If not, I assume cURL?
#2

[eluser]mlage[/eluser]
I don't understand your question...

If your wondering how to access the URL's data, you need to look into the URI class (http://ellislab.com/codeigniter/user-gui...s/uri.html)

example URL (from CI documentation): index.php/user/search/name/joe/location/UK/gender/male
Code:
$array = $this->uri->uri_to_assoc(3); //3 represents the number of parts of the URL to obtain
$array looks like this after the call:
[array]
(
'name' => 'joe'
'location' => 'UK'
'gender' => 'male'
)

There are more methods of the uri class... so if this doesn't satisfy your need, i bet one of the others will
#3

[eluser]jmanpa[/eluser]
I'm calling a function, like:

http://mysite.com/returnsomedata

and get JSON back.

I'm trying to figure out if CI has an abstracted library to make the call or do I just use basic PHP curl_exec.
#4

[eluser]mlage[/eluser]
http://codeigniter.com/wiki/JSON_Helper/

Does that help? From my understanding... you have a php script on your server which your sending a HTTP request to for some data to be returned... so ... I'm not sure if CI has the code to do this... perhaps checking out the load library...

I would include the file, which would have a class declaration in it... (make sure the file doesn't allow direct access to it by users by checking to see if BASEPATH is defined) and then get an instance of the class and run the function... and return it
#5

[eluser]InsiteFX[/eluser]
As of PHP 5 JSON encode and decode is included in the PHP core!

InsiteFX
#6

[eluser]jmanpa[/eluser]
I'm not concerned about JSON encoding/decoding.
I'm talking about the HTTP call. This seems like something CI should have a helper for (for less code reasons):

// create a new cURL resource
$ch = curl_init();

// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "http://www.example.com/");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch)
// close cURL resource, and free up system resources
curl_close($ch);
#7

[eluser]mlage[/eluser]
why don't you write the helper file Wink

Sorry I couldn't help more... did you check the wiki ?




Theme © iAndrew 2016 - Forum software by © MyBB