CodeIgniter Forums

Full Version: Can't Find Library/Helper/Class in CI
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[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?

El Forum

[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

El Forum

[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.

El Forum

[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

El Forum

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

InsiteFX

El Forum

[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);

El Forum

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

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