Including the phpFlickr library in Kohana
I'm beginning a website using the Kohana Framework, and I couldn't find how to include external libraries "the proper way".
I want to use the php开发者_高级运维Flickr library to allow my website to interact with Flickr.
If there was a better way to include the files than:
require_once("path/to/phpFlickr.php");
// Fire up the main phpFlickr class
$f = new phpFlickr($key);
It's OK to do it that way I guess, but if I could say to Kohana, "the phpFlickr files are there, go get them on your own when you need it", it would be better.
Anyone can help me with that?
Thanks.
We use it in the same way as detailed here. So, like the following:
$path = Kohana::find_file('vendors', 'flickr/phpFlickr');
if($path) {
ini_set('include_path',
ini_get('include_path') . PATH_SEPARATOR . dirname(dirname($path)));
require_once 'flickr/phpFlickr.php';
}
You can make a flickr folder in modules, create an init.php file in there and do something like this;
require_once Kohana::find_file('folder','phpFlickr');
Of course, you'll first have to enable "flickr" module in your bootstrap.
The better way would be to define a custom autoload method for flickr classes only so it's loaded only when it's actually needed.
精彩评论