DMZ - How to resolve object naming conflict? |
[eluser]nottRobin[/eluser]
I'm using DataMapper OverZealous Version (DMZ) for my Object Relational Mapping. The standard way of instantiating a Model object 'participant' in DMZ is: Code: var $participant = new Participant(); However, this doesn't work if my controller class has the same name, because it will return an instance of the class itself: Code: class Participant extends Controller { This is frustrating as it's quite important, semantically, for my site that both the Model and the Controller are called "participant". Does anyone know how I can access the DMZ Model object in another way or something? Thanks, Robin.
[eluser]nottRobin[/eluser]
The Model can actually be named anything, so the solution I've gone with for the time being is to prefix all my model classes with 'Model_'. It's not an ideal solution as it requires a fair bit of extra typing, and extra code, as all my relationships now have to be explicitly defined: Code: class Model_participant extends DataMapper { This then allows my controller to work fine: Code: class Participant extends Controller { I'd still love a more elegant solution though, so I don't have to write all the extra code.
[eluser]jayrulez[/eluser]
using php native namespace can remedy the situation.
[eluser]nottRobin[/eluser]
Thanks jayrulez. I was wondering about that. Can you show me how that would work? Is it this? PHP Namespaces overview In which case it's only available in PHP 5.3 onwards. I'm a bit wary of 5.3 as it causes problems with some other PHP sites I'm running. Do you know if there's a way to simulate namespaces in PHP 5.2?
[eluser]nottRobin[/eluser]
I installed PHP 5.3.2 just so I could take advantages of namespaces. Then I added "namespace Model;" to the top of my Model class. Code: namespace Model; Code: class Participant extends Controller { Code: Fatal error: Class 'Model\Model_participant' not found in /path/to/application/controllers/participant.php on line 22 I don't think there's an easy solution to this so I should probably give up. If anyone does have any suggestions please go ahead and let me know Robin.
[eluser]oooobs[/eluser]
[quote author="nottRobin" date="1268821410"]I installed PHP 5.3.2 just so I could take advantages of namespaces. Then I added "namespace Model;" to the top of my Model class. Code: namespace Model; Code: class Participant extends Controller { Code: Fatal error: Class 'Model\Model_participant' not found in /path/to/application/controllers/participant.php on line 22 I don't think there's an easy solution to this so I should probably give up. If anyone does have any suggestions please go ahead and let me know Robin.[/quote] I have the same problem? I wish I know how to solve this Datamapper namespace issue |
Welcome Guest, Not a member yet? Register Sign In |