Kohana找不到我的控制器,路线错了?

时间:2012-02-14 11:26:17

标签: kohana kohana-3

我还在和Kohana一起玩,并为我找到另一个塞子: - )

我创建了一个名为compte.php的新简单控制器,位于/app/classes/controller/compte.php

<?php defined('SYSPATH') or die('No direct script access.');

class Controller_Compte extends Controller {

public function action_index()
{
    $this->response->body('hello, world comptes!');
}
} // End Comptes

为什么我不能用这个网址转到这个控制器?

http://127.0.0.1/~user/kohana/compte/

此网址有效:

http://127.0.0.1/~user/kohana/

我已经在bootstrap.php文件中编辑了路由但没有成功,确定我遗漏了一些东西......

如果我使用默认路由指向我的控制器comptes,我可以看到它没问题,但我想知道如何直接转到这个控制器。

 Route::set('compte', '()') ->defaults(array( 'controller' => 'compte', 'action' => 'index', ));

谢谢!

修改

我从Web服务器收到错误404 Not Found错误,而不是来自Kohana

编辑2

# Turn on URL rewriting
RewriteEngine On

# Installation directory
RewriteBase /~user/kohana/

# Protect hidden files from being viewed
<Files .*>
    Order Deny,Allow
    Deny From All
</Files>

# Protect application and system files from being viewed
RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]

# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT]

此外,该文件与examples.htaccess位于同一级别,但在kohana文件夹中重命名为.htaccess

编辑3

我第三次关注教程链接,最初的问题是Apache,现在404来自Kohana:

HTTP_Exception_404 [ 404 ]: Unable to find a route to match the URI: compte

这是我在bootstrap.php中唯一的路线

 Route::set('compte', '') ->defaults(array( 'controller' => 'compte', 'action' => 'index', ));

如果我输入没有任何控制器的URL,我可以看到默认的compte Controller,但是如果我使用compte或comptes或者其他什么,总是找不到404 ...

3 个答案:

答案 0 :(得分:1)

关于编辑3:

您的路由仅匹配空URI字符串。 'compte'或'comptes'不是空字符串。 如果您希望路由匹配空URI以及URI'compte'和'comptes',请使用以下命令:

Route::set('compte', '(compte(s))')
    ->defaults(array(
        'controller' => 'compte',
        'action' => 'index',
    ));

整个事情是可选的,因此它可以匹配空URI。一旦'compte'存在,'s'也是可选的。一旦你了解路由就非常强大,你可以here

答案 1 :(得分:0)

尝试

Route::set('compte', '') ->defaults(array( 'controller' => 'compte', 'action' => 'index', ));

请注意,网址部分为空。

答案 2 :(得分:0)

也许Apache没有配置为读取.htaccess文件。阅读&#34; 404错误&#34;部分:https://github.com/kohana/core/blob/962c5f12714cb3ab146a41db61a888c2b0cc79da/guide/kohana/tutorials/clean-urls.md

相关问题