Kohana 3.2 controllers in classes / controllers / <subfolder> / <subfolders>
I have already seen many questions that are very similar to this question (like this and this ), but my problem is that I have my controllers in a subfolder inside a folder inside the controllers folder. My directory structure looks like this:
classes/ controllers/ admin/ manageMemberProfile/ memberList.php memberProfileInfo.php editMemberProfile.php manageCompanyProfile/ ........ member/ ........ guest/ ........ models/ ........
Please note that I already made this solution in the link I provided (and I managed to do it), but just for the controllers that are in a folder inside the controllers folder. I want to call my controllers with directory setup like this. I'm completely new to routing in kohana 3.2, so I really don't know how to solve this, and I also read their routing documentation, but I still can't seem to solve this problem.
source share
The answers given in the links also work here. You just need to add a subdirectory for example. like this
Route::set('admin_manageMembersProfile', 'admin/manageMembersProfile(/<controller>)') ->defaults(array( 'directory' => 'admin/manageMembersProfile', 'controller' => 'defaultController', 'action' => 'defaultAction', ));
Of course, it will be very important to do this for each subdirectory. This way you can use Lambda / Callback route logic :
Route::set('admin', function($uri) { $directories = array('manageMembersProfile', 'manageOthers'); if (preg_match('#^admin/('.implode('|', $directories).')(/[^/]+)*#i', $uri, $match)) { $subdirectory = $match[1]; if (array_key_exists(2, $match)) { $controller = trim($match[2], '/'); } else { $controller = 'defaultController'; } if (array_key_exists(3, $match)) { $action = trim($match[3], '/'); } else { $action = 'defaultAction'; } return array( 'directory' => 'admin/'.$subdirectory, 'controller' => $controller, 'action' => $action, ); } });
This is just a very basic example, but I hope it shows how you can handle routing this way.
source share