Posts Tagged ‘doctrine’

Doctrine vs Codeigniter (classname collitions)

Sunday, October 5th, 2008

Doctrine is really nice, but upon generating schemas the generated classes are a bit “general”. For example I have a User, a Post and a PostTag table, after building the schema I will end up with similar classnames (no, renaming does not work). Yes, this is cute on one hand (new User), but on the other if I happen to have a User class in my controllers (not terribly hard with Codeigniter) then whoops, I have a classname collition where finetuning the autoloader will not help. Possible solutions:

  • rename the generated models: not a good idea, will throw nice fat errors (‘Couldn’t find class User’), there maybe a solution for this, but I really doubt it
  • rename the controller: pain in the back with Codeigniter (and routing), no thanks
  • finetune CI so that Controllers have a distinct name (UserController), with routing made aware of this fact (/user/ routes to UserController); this is buried in the CI core code, no thanks again. Also User_Controller would be nice, Kohana seemed to understand this.
  • set up custom routes for conflicting classes: CI route-manager is a bit dumb, finetuning routing for all cases does hurt. One can set up url rewriting too, but that’s even more pain in the back, because of the internal routing and redirection schemes.
  • use namespaces, which is possible with PHP5.3 (currently alpha 2), but namespacing the whole Doctrine system and ironing out class declaration problems is beyond my knowledge (though I must admit it, I tried).