Author: Daniel Vecchiato (danfreak)
This tutorial will introduce you to an easy way to integrate the Zend Framework libraries (a lot!) into Code Igniter php Framework.
In particular we will build an example in wich we use the Zend_Service_Flickr to retrieve images based on a specific tag ('climbing' in this tutorial).
We didn't test all Zend Framework libraries with Code Igniter, therefore we can't ensure that this integration will work with all of them.
Your system/application/my_classes/ directory will look as follows
my_classes/
|-Zend.php
|-Zend/
|-Acl.php
|-Auth.php
|-etc.
|-Acl/
|-Auth/
|-etc.
/*
|--------------------------------------------------------------------------
| Enable/Disable System Hooks
|--------------------------------------------------------------------------
|
| If you would like to use the "hooks" feature you must enable it
by
| setting this variable to TRUE (boolean). See the user guide for
details.
|
*/
$config['enable_hooks'] = TRUE;
$hook['pre_controller'][] = array(
'class' => 'MyClasses',
'function' => 'index',
'filename' => 'MyClasses.php',
'filepath' => 'hooks'
);
<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
class MyClasses
{
/**
* includes the directory application\my_classes\ in your includes
directory
*
*/
function index()
{
//includes the directory
application\my_classes\
//for windows tests change the ':'
before BASEPATH to ';'
ini_set('include_path',ini_get('include_path').':'.BASEPATH.'application/my_classes/');
}
}
?>
Be carefull to change the colon ':' to semicolon ';' if you use the above hook while running PHP and Apache on a Windows platform
PHP/Apache on Windows platform:
//Windows
ini_set('include_path', ini_get('include_path').';'.BASEPATH.'application/my_classes/')
PHP/Apache on Linux platform:
//Linux
ini_set('include_path', ini_get('include_path').':'.BASEPATH.'application/my_classes/')
<?php
class Flickr extends Controller
{
function Flickr()
{
parent::Controller();
}
function index()
{
require_once('Zend/Service/Flickr.php');
$flickr = new
Zend_Service_Flickr('YOUR_FLICKR_API_KEY HERE');
try
{
$results = $flickr->tagSearch("climbing");
if ($results->totalResults() > 0)
{
foreach ($results as $result)
{
echo '<img src="'.$result->Square->uri.'"
/>';
}
}
else
{
echo '<p style="color: orange; font-weight:
bold">No Results Found.</p>';
}
}
catch (Zend_Service_Exception $e)
{
echo '<p style="color: red; font-weight: bold">An error
occured, please try again later. (' .$e->getMessage().
')</p>';
}
}
}
?>
now point your browser to http://www.your_website.com/flickr and you should see a bit of colourfull images!