hello,
I tested with libraries and Controllers, but not Models ...
I thought it was good lol, at the same time this is new for me.
After testing, namespaces do not work in Models, but this is not too worried because we know still use them.
The reason that I decided to modify core files is because I’m working with hmvc extension, and class collision is more probable. For this reason I also modified hmvc extension.
Then you can work with namespaced hmvc:
namespace controllers\blog
class user extends \CI_Controller {
public function get_comments($id_user){
/* Code */
//[1]
$module = $this->load->module('namespace\modulename/classname');
//[2]
$module->method($x, $y);
// OR [3]
\Modules::run('namespace\modulename/classname/method', $x, $y);
}
}
$_ns = __NAMESPACE__;
Wich is the advantage?
Well, with hmvc you can work with micro-applications, for example:
modules/blog
modules/wiki
And is probable that both modules (micro-applications) has a class called User. If you need use a blog/user class into a wiki/user class, is posible a name collision, but using the patch you don’t need woory about this:
namespace wiki
class user extends \MX_Controller{
// Code.
$user_blog = $this->load->module('blog\user');
$user_blog->get_info();
// Code.
}
I’m going continue investigate how to make possible namespace support for modules.
I hope that it help you! Thanks.
More info:
http://porquero.blogspot.com/2012/03/codeigniter-hmvc-namespaces-part-2.html