Routing Subfolders

koseven
routes
#1

Koseven Route to use with sub-folder. Example if you want to Route /admin/user/edit or /admin/article/edit to:

- admin
 - user
  - edit.php
 - article
  - edit.php

According Route would be:

Route::set('admin', 'admin/<directory>(/<controller>(/<action>(/<id>)))',
  array(
    'directory' => '(user|article)'
  ))
  ->defaults(array(
    'controller' => 'edit',
    'action'     => 'index',
  ));
#2

Do you know the code quality measure: WTF per minute? So the example given is illogical. You want to have Controller_Admin_User_Edit and action index

In routing, you are not limited to parameters called directory, controller, action, id. You can enter any and use filters to modify the input parameters. In addition, in Controller::before (), you can overwrite Route::action().

Eg my before form API:

      protected $_action_map = array
      (
              HTTP_Request::GET    => 'index',
              HTTP_Request::PUT    => 'update',
              HTTP_Request::POST   => 'create',
              HTTP_Request::DELETE => 'delete',
      );
    public function before() {
          $this->_action_requested = $this->request->action();
          $method = Arr::get($_SERVER, 'HTTP_X_HTTP_METHOD_OVERRIDE', $this->request->method());
          $this->request->action($this->_action_requested.'_'.$this->_action_map[$method]);
          return parent::before();
    }
#3

Dear @bato3:

First of all thanks for joining our community :slightly_smiling_face:

Do you know the code quality measure: WTF per minute?

I do…please keep in mind this is only a Forum. This is not an official documentation or anything like that. Anyone is free to register and can post guides here or other stuff related to koseven. So there are no Code Reviews for forum posts. This one was just a quick (and as you would say dirty) example of how you could do it…which we created a while ago in the Telegram chat and posted it here.

So the example given is illogical

In my opinion it pretty much does what it sould do, enabling Routes for subfolders in a easy way.

In routing, you are not limited to parameters called directory, controller, action, id. You can enter any and use filters to modify the input parameters.

indeed you can and i am pretty sure via this way there is a “better” solution for my code above (one that even works with multiple sub directories and so on) but as said this was just a quick example of how you could do it.

Anyway: I really appriciate your help and input and i hope it is useful for others in the future. Thanks a lot! :smiley:

#4

I use 3 apps: backend, frontend, common (cms core).
For big projects need add routes for index/list action with paginate/sort params:
admin/<directory>/<controller>(/<page>(/<sort_column>-<sort_direction>)) and without directory: admin(/<controller>(/<action>(/<id>))) + admin/<controller>(/<page>(/<sort_column>-<sort_direction>)), also i wrap directory in (): admin(/<directory>(/<controller>(/<action>(/<id>)))). + set filter for check directory/controller in FS.