2012-03-14 99 views
1

您好我在匹配Kohana 3自定义路由时遇到问题,似乎每件事情都是正确的,但URL与路由不匹配。以下是我的bootstrap.php文件中的设置:Kohana 3 route not matching

Kohana::init(array(
'base_url' => '/basepath/', 
    'index_file' => 'index.php' 
)); 

    /** 
    * Attach the file write to logging. Multiple writers are supported. 
    */ 
    Kohana::$log->attach(new Log_File(APPPATH.'logs')); 

    /** 
    * Attach a file reader to config. Multiple readers are supported. 
    */ 
    Kohana::$config->attach(new Config_File); 

    /** 
    * Enable modules. Modules are referenced by a relative or absolute path. 
    */ 
    Kohana::modules(array(
'auth'  => MODPATH.'auth',  // Basic authentication 
// 'cache'  => MODPATH.'cache',  // Caching with multiple backends 
// 'codebench' => MODPATH.'codebench', // Benchmarking tool 
'database' => MODPATH.'database', // Database access 
'image'  => MODPATH.'image',  // Image manipulation 
'orm'  => MODPATH.'orm',  // Object Relationship Mapping 
// 'unittest' => MODPATH.'unittest', // Unit testing 
'userguide' => MODPATH.'userguide', // User guide and API documentation 
)); 


     /** 
     * Set the routes. Each route must have a minimum of a name, a URI and a set of 
     * defaults for the URI. 
     */ 
    Route::set('default', '(<controller>(/<action>(/<id>)))') 
->defaults(array(
    'controller' => 'welcome', 
    'action'  => 'index', 
)); 

    Route::set('category_images', 'cat/<category>', array('category'=>'[a-z\-_\.]+')) 
->defaults(array(
    'controller' => 'categoryimages', 
    'action'  => 'index', 
)); 

    Route::set('user_images', '<username>/images(/<pageid>)', array('username'=>'[a-z\-_\.]+', 'pageid'=>'[1-9][0-9]*')) 
->defaults(array(
    'controller' => 'userimages', 
    'action'  => 'index', 
)); 




    Route::set('dynamic_image', 'image/thumbnail/<size>/<id>/<image>', array('size'=>'s|m|z', 'id'=>'[0-9]+', 'image'=>'.+')) 
->defaults(array(
    'controller' => 'image', 
    'action' => 'thumbnail' 
)); 

附上错误mesage:enter image description here

下面是目标控制器,显示命名约定,如果有问题,即:

<?php 

class Controller_Categoryimages extends Controller_Template { 

    public $template = 'template'; 
public $images_per_page = 15; 

// show images of a user 
    public function action_index() { 
     //code here 
    } 

请告诉我们,如果有人知道它为什么不匹配URL。

在此先感谢你们。

+0

你试图访问什么网址?浏览器截图中的地址难以辨认。 – Dickie 2012-03-14 22:20:08

+0

这一个'http:// localhost/basepath/index.php/cat/sky' – Hafiz 2012-03-14 22:21:54

回答

1

你的默认路线应该是最后的,因为它是一个全部。我建议你完全删除它。它目前首先与默认匹配,并尝试使用动作天空加载Contoller_Cat类。

+0

如果我将它删除,那么默认的控制器和动作将如何工作?我应该把它带到文件结尾 – Hafiz 2012-03-14 22:29:44

+0

你应该为你的其他控制器制定更具体的路线。如果你不喜欢这个想法(最终你可能会这么做),只需要坚持你的默认路线。 – zombor 2012-03-14 22:32:52