Welcome Guest, Not a member yet? Register   Sign In
Codeigniter + namespaces
#9

[eluser]porquero[/eluser]
[quote author="Noobigniter" date="1332609235"]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.[/quote]

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:

Code:
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:

Code:
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/cod...art-2.html


Messages In This Thread
Codeigniter + namespaces - by El Forum - 03-06-2012, 07:55 PM
Codeigniter + namespaces - by El Forum - 03-21-2012, 08:32 PM
Codeigniter + namespaces - by El Forum - 03-21-2012, 10:07 PM
Codeigniter + namespaces - by El Forum - 03-21-2012, 11:04 PM
Codeigniter + namespaces - by El Forum - 03-22-2012, 12:05 PM
Codeigniter + namespaces - by El Forum - 03-22-2012, 12:11 PM
Codeigniter + namespaces - by El Forum - 03-24-2012, 10:13 AM
Codeigniter + namespaces - by El Forum - 03-27-2012, 11:21 PM
Codeigniter + namespaces - by El Forum - 03-28-2012, 06:38 AM



Theme © iAndrew 2016 - Forum software by © MyBB