I'm using great I have different user levels and to load the right controllers, I am using Namespace in class.
$ di-> Set ('Dispatcher', function) (// Create a EventMager $ Event Manager = New Event Manager (); // Removing Extensions Before Events- Remove Extensions Manager- & Gt; Attach ("Send: First Dispatch Loop", Function ($ Event, $ Sender) {Switch ($ user-> GetUserType ()) {Case 1: // Student $ Dispatcher-> SetNomespaceName (' Student '); break; case 2: // userlevel 2, still to come; 3: // admin & amp;; minion $ sender- & gt; setNamespaceName (' admin ');}}); $ Sender = New MvcDispatcher (); $ Sender-> Set Events Manager ($ Event Manager); $ Sender;});
Namespace is register like this:
$ loader-> Register Namespace (array ('student' = & gt; __DIR__. /../../app/controllers/student ',' Admin '=> __DIR__. / /../app/controllers/admin),
);
This works very well, but now I want subdirectories like ".. Controllers / Administrators / sub". Namespaces should also be in "Administrator" in the controller "/ sub". (Due to the sender) or can I do something like name space in some way admin / * and php include all subdirectories?
I hope that I can explain my problem and someone can help you =)
IMHO, the best way to do this will be in the Router logic domain - your dispatcher has been asked to send a reminder, and your router learns what to send and tells the sender that both of you Are mixing between. I will override the extension of the router, the handle method and set the name space from there. The router must be registered with DI (otherwise the base will be used).
public function handle ($ uri = null) {origin: handle ($ uri); Switch ($ user-> getUserType ()) {Case 1: // student $ $ this- & gt; _namespace = 'student'; break; Case 2: // UserLate 2, yet to come; Case 3: // Admin & amp; | Minion $ this- & gt; _namespace = 'admin'; break; }}
For the real question - it is also related to your routing methods. You need to specify a sub or you can do it in the handle function as below. I tested and it works, but it would be better to keep a logical argument referred to in the paths in one place.
Handle public function ($ uri = null) {$ this- & gt; _ Controller = 'all \\' $ this- & gt; _controller; } Edit: Besides, maybe what you want to hear but having sub folders for your controllers is probably not the best way to move forward. I do not know what is a best practice, but to keep them flat in one directory per one module is really a real guess. You can do many modules with your own controllers, Falcon supports multimode.
Comments
Post a Comment