bmcclure / CakePHP-Menu-Plugin

A CakePHP 2.0 plugin designed to help build menus in the controller and display them in the view
MIT License
17 stars 9 forks source link

Menu class conflicts with model class named Menu #11

Closed bmcclure closed 12 years ago

bmcclure commented 12 years ago

As referenced in #5

The MenuLib library included with the plugin currently registers itself with Cake's autoloader to avoid Class Not Found errors.

This means any model class (or other class) with the same name as a class within MenuLib could potentially conflict (you could get an instance of a MenuLib class when you want a model class, for instance).

To resolve this, I'm going to try to implement namespaces within MenuLib, and always refer to MenuLib's classes using the namespace path.

bmcclure commented 12 years ago

Namespaces have been implemented. All references to the Menu class (and all classes within MenuLib) are now fully namespaced, so not more class name conflicts should be possible with app classes.

Make sure to load the Menu plugin's bootstrap file so that it can instantiate MenuLib's classloader.

Let me know if there are further issues with conflicts, or if this change has caused any problems I haven't noticed.

Fuhrmann commented 12 years ago

This is working great. Thank you. What I've done to load the plugin now, is this:

CakePlugin::load(array('Menu' => array('bootstrap' => true)));

bmcclure commented 12 years ago

Perfect. I'm very glad to hear this is working now--I plan to follow this same pattern in my AutoAsset plugin (and any future plugins including their own generic libraries) to avoid possible name conflicts.

Let me know if you run into any further issues!

Ben