I have multiple libraries created in application/libraries for the APIs I use.
APIs:
- Vimeo
- Flickr
Now I have created in application/modules/apis/controllers/vimeo.php and application/modules/apis/controllers/flickr.php that will interact with the libraries upon request by the other modules.
The problem is that now I redeclare the classes:
-
libraries/Flickr.php:
Class Flickr { } -
modules/apis/controllers/flickr.php:
Class Flickr extends MX_Controller { }
So I get in my apache2’s error log: Cannot redeclare class Flickr in ...
EDIT:
So having in my modules/apis/controllers/flickr.php file:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Class Flickr extends MX_Controller { ... }
How should I use:
namespace controllers\blog
class user extends \CI_Controller {
explained here: http://codeigniter.com/forums/viewthread/212661/ ?
Tried doing:
<?php
//TRIED:
namespace controllers\flickr;
namespace Flickr;
namespace modules\apis\controllers\flickr;
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Class Flickr extends \MX_Controller { ... }
$_ns = __NAMESPACE__;
But I get no response from a simple function that echoes out ‘alex’ and no error in my log calling the controller and function.
PHP 5.3 added support for namespaces. CodeIgniter doesn’t support them yet though, but I did find a recent forum post that claims to have a patch that will allow you to use them.
http://codeigniter.com/forums/viewthread/212661/