EllisLab text mark
Advanced Search
     
Codeigniter + namespaces
Posted: 06 March 2012 09:55 PM
Avatar
Joined: 2011-06-12
69 posts

I’ve patched CI to make support namespaces. Only replace Codeigniter.php file with patch. And Code your controllers:

namespace controllers\blog

class user extends \CI_Controller {
  
public function get_comments($id_user){
     
// Code  
  
}
}

$_ns 
__NAMESPACE__

Download patch:
http://dl.dropbox.com/u/315893/blog/CI+HMVC+NS/CodeIgniter.php

More info:
http://porquero.blogspot.com/2012/03/codeigniter-hmvc-namespaces-part-1.html

 Signature 

Web developer with open source soul
Blog: porquero.blogspot.com

 
Posted: 21 March 2012 11:32 PM   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2010-08-13
77 posts

Thank you, works fine…

 
Posted: 22 March 2012 01:07 AM   [ # 2 ]   [ Rating: 0 ]
Avatar
Joined: 2009-06-19
6706 posts

Now what do you think is going to happen when you upgrade CodeIgniter?

You never touch the CodeIgniter core files!

 Signature 

Certified State of CT Computer Programming Teacher.
Custom Designed Icons, eBook Covers Software Boxes. CD, DVD Etc. New iPhone® Tab Bar Icons and iPhone® Applications Icons.

Skype: insitfx

STOP! Before posting your questions, remember the WWW Golden rule:
What did you try? What did you get? What did you expect to get?

Input -> Controller | Processing -> Model | Output -> View

 
Posted: 22 March 2012 02:04 AM   [ # 3 ]   [ Rating: 0 ]
Avatar
Joined: 2010-08-13
77 posts

Hi,

Yes, I realize it will take (or not?) Make changes in an update, but it was also the case in the files of my application (Model => CI_Model, ...).
The change only two lines codeigniter.php.
I put it on github as “personal” backup.
If you want to see the changes.
(This is mainly to test namespaces story to learn.)

 
Posted: 22 March 2012 03:05 PM   [ # 4 ]   [ Rating: 0 ]
Avatar
Joined: 2011-06-12
69 posts
InsiteFX - 22 March 2012 01:07 AM

Now what do you think is going to happen when you upgrade CodeIgniter?

You never touch the CodeIgniter core files!

CI 2 hasn’t full support for php5.3, so meanwhile. And I understand that the next version will be 3.

 Signature 

Web developer with open source soul
Blog: porquero.blogspot.com

 
Posted: 22 March 2012 03:11 PM   [ # 5 ]   [ Rating: 0 ]
Avatar
Joined: 2011-06-12
69 posts
Noobigniter - 22 March 2012 02:04 AM

Hi,

Yes, I realize it will take (or not?) Make changes in an update, but it was also the case in the files of my application (Model => CI_Model, ...).
The change only two lines codeigniter.php.
I put it on github as “personal” backup.
If you want to see the changes.
(This is mainly to test namespaces story to learn.)

Thanks for test it, I accept any feedback.

I tried to make Model support NS but I could not do it.

 Signature 

Web developer with open source soul
Blog: porquero.blogspot.com

 
Posted: 24 March 2012 01:13 PM   [ # 6 ]   [ Rating: 0 ]
Avatar
Joined: 2010-08-13
77 posts

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.

 
Posted: 28 March 2012 02:21 AM   [ # 7 ]   [ Rating: 0 ]
Avatar
Joined: 2011-08-28
139 posts
porquero - 06 March 2012 09:55 PM

I’ve patched CI to make support namespaces. Only replace Codeigniter.php file with patch. And Code your controllers:

namespace controllers\blog

class user extends \CI_Controller {
  
public function get_comments($id_user){
     
// Code  
  
}
}

$_ns 
__NAMESPACE__

Download patch:
http://dl.dropbox.com/u/315893/blog/CI+HMVC+NS/CodeIgniter.php

More info:
http://porquero.blogspot.com/2012/03/codeigniter-hmvc-namespaces-part-1.html

If this is merged to official release, CodeIgniter will be better. Just add “action_index” instead of “index”, and it will be (may be) as good as FuelPHP

 Signature 

Homepage : http://www.getnocms.com
Github page : https://github.com/goFrendiAsgard/No-CMS

A free CodeIgniter based CMS-Framework, It is not just another CMS !!!

 
Posted: 28 March 2012 09:38 AM   [ # 8 ]   [ Rating: 0 ]
Avatar
Joined: 2011-06-12
69 posts
Noobigniter - 24 March 2012 01:13 PM

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

 Signature 

Web developer with open source soul
Blog: porquero.blogspot.com