0

I have a:

// administration
app/controller/admin/ProjectsController.php

And I want use too:

// public in website
app/controller/ProjectsController.php

But, in autoload_classmap.php, it's registred like that:

'ProjectsController' => 'app/controller/admin/ProjectsController'

So, If I want one more 'ProjectsController' for public views, how I need to do?
What is better? 2 controllers (admin and public), or one (hybrid).

Thanks.

Marek Skiba
  • 2,124
  • 1
  • 28
  • 31
Patrick Maciel
  • 4,874
  • 8
  • 40
  • 80

1 Answers1

3

You should namespace your Admin controllers.

That way it'll match up to PSR and autoloader will treat them differently.

namespace Admin;

At the top of your admin files.

Edit:

It may even be worth namespacing all your controllers and models.

So for your ProjectController in app\controllers you could put

namespace ProjectName

Then for everything in subfolders, e.g. app\controllers\admin

namespace ProjectName\Admin

and so on for other folders, and files.

This'll reduce the likely hood of your code clashing with anything else.

Edit: Edit:

After namespacing classes you'll need to reference classes and functions that are outside your namespace. For example Controller belongs to the global namespace so you put \ at the start of Controller.

The documentation here should help out a lot. PHP Namespaces

Aran
  • 3,298
  • 6
  • 32
  • 33