Welcome Guest, Not a member yet? Register   Sign In
Controllers in modules with same names
#1

I downloaded an extension for modules in CI. I have a controllers->cars and modules->admin->cars2, because I coudn't name them with same name. I'm thinking that I wont be able to create other modules that will have controllers names that are somewhere used as class name.

Is there some solutions alternatives to it?

What is the worst about it, that URI you have to write mysite.com/cars and mysite.com/admin/cars2, not cars.
Reply
#2

What sort of extension are you talking about? HMVC kind? If the answer is yes, why can't you just move the controllers from controllers folder into their respective modules?
Reply
#3

You cannot have two classes with the same name. Only way around this is the new namespaces, which CI doe's not use yet.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#4

(This post was last modified: 01-09-2015, 12:56 PM by mwhitney. Edit Reason: typo )

There are methods other than namespacing which would allow you to have two classes with the same name. Additionally, even without special methods to access the classes, two controllers can easily use the same class name if they are not intended to interact with one another. Of course, because of the potential for issues, I wouldn't really recommend it.

For example, Bonfire uses Wiredesignz HMVC and a "Context" system which allows you to setup different controllers for use in the admin section of the site. By default, the contexts are called "Content", "Reports", "Settings", and "Developer". Each module can use a controller named after the context, and the controller can be referenced via the URL mysite.com/admin/{context}/{module}, which will load the file in /application/modules/{module}/controllers/{context}.php. This leads to a proliferation of files named content.php, reports.php, settings.php, and developer.php on a large site, each of which is a controller with a class name of "Content", "Reports", "Settings", or "Developer", with no namespacing.

Since they're controllers, the only time this is really an issue is when you start accessing other controllers via HMVC. Even then, the HMVC loader and Modules library can usually discern between the controllers when using the proper HMVC methods for making those calls and reduce the potential for problems.

Additionally, namespaces can be used in your application, they just aren't directly supported by the loader in CodeIgniter.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB