I'm quite new to Kohana and was wondering what the best way was of organising a lot of files in the application/classes/controller directory.
My current structure is:
-application
--classes
---controller
----page
-----test.php
And I want to call the page from a url without it needing the page or optionally the name of any other subdirectory:
www.w开发者_如何学运维ebsite.com/test/
My controller class starts:
<?php defined('SYSPATH') OR die('No direct access allowed.');
/**
* Test
*
* @package Test
* @category Page
* @author
*
*/
class Controller_Page_Test extends Controller_Template {
// Default
public function action_index() {
// Template vars
}
}
What do I need to do to avoid the 404 error it is throwing? I assume I need to set up a route in bootstrap.php but I don't really get what to do to allow the pages to activate from within subdirectories.
Thanks in advance.
Use directory
param in Routes:
Route::set('with_dir',
'test(/<action>(/<id>))',
)
->defaults(array(
'directory' => 'page',
'controller' => 'test',
));
You can use regex for controller list. For example, you have Controller_Test and Controller_Foo in a page directory. Here is a route for it:
Route::set('with_dir',
'<controller>(/<action>(/<id>))',
array(
'controller' => '(test|foo)',
))
->defaults(array(
'directory' => 'page',
'controller' => 'test',
));
精彩评论