How can I create the Route in Kohana 3.2 for this

2019-03-06 15:25发布

问题:

I'm using Kohana 3.2 and I need to create the directory structure below for my application. For that, I'm using the Route below, but I'm doing something wrong yet. "Settings" is my use case that I'm developing.

<?php
Route::set('global', '<directory>(/<controller>(/<action>))', array('directory' => 'settings'))
    ->defaults(array(
        'directory' => 'settings',
        'controller' => 'settings',
        'action' => 'index',
    ));
?>

So, this is my directory structure for "Settings" use case:

   - ..\application\settings\classes\controller\settings.php
   - ..\application\settings\classes\model\settings.php
   - ..\application\settings\views\settings_form.php

And this is the code for my controller:

   class Controller_Settings extends Controller {

       public function action_index(){
           echo 'test';
       }
   }

And this is the url that I'm using to access my controller:

   - http://cmx107/clients/cmcaapp/v1/settings

Thanks, Cheers

回答1:

Since you set directory to default to settings, you need to put your controller Settings in the Settings directory like this rather than the way you did it:

Paths

Correct: application/classes/settings/settings.php

Format: apppath/classes/<directory>/<controller>.php

Class Controller_Settings_Settings extends Controller {
    public function action_index(){
       echo 'test';
   }
}