class name collision when using codeigniter 2.0 with Datamapper? class name collision when using codeigniter 2.0 with Datamapper? codeigniter codeigniter

class name collision when using codeigniter 2.0 with Datamapper?


One of the drawbacks in CodeIgniter is that you cannot name a controller, model or library the same thing. This is mainly a PHP issue as obviously you cannot name anything the same, but it can be avoided in two ways.

  1. PHP Namespaces - no can do, they are PHP 5.3 only and 90% of the community would kick off if they were implemented.
  2. Controller Prefixes - This is something I would love to add, but... well it would break stuff for everyone. We'll have to wait until 2.1 at least for a change that big.

For now all I can recommend is you name your models and libraries carefully.

Controller - Users
Library - User
Model - User_model | User_m

It's annoying, but just one of those things for now.


so using the “user” model within the “user” controller is imposible!!

Umm no it isn't, you need to check the UserGuide more carefully ;)

You may give your model a name other than what it is orginaly defined as:

If you would like your model assigned to a different object name you can specify it via the second parameter of the loading function:

$this->load->model('Model_name', 'fubar');    $this->fubar->function();


All you need to do is change your controller file name and class name to "Users". You don't need to change your model name.

controller: users
model: user
db table: users

Take a look at the Datamapper docs.