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

发布于 2025-01-04 23:51:02 字数 1940 浏览 1 评论 0原文

我仍在玩 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 控制器,但如果我使用 compte 或 comptes 或其他什么,总是 404 not found ...

I'm still playing with Kohana, and found another stopper for me :-)

I've created a new simple controller called compte.php and is located inside /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

Why I can't go to this controller with this url?

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

This url works:

http://127.0.0.1/~user/kohana/

I've edited the routes in the bootstrap.php file but without success, sure I'm missing something ...

If I use the default route to point to my controller comptes, I can see it ok, but I want to know how to go directly to this controllers.

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

thanks!

EDIT

I'm getting the error 404 Not Found error from Web Server, not from Kohana

EDIT 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]

Also the file is located at the same level as the examples.htaccess but renamed to .htaccess, in the kohana folder

EDIT 3

I've followed for third time the tutorial linked, the initial problem was with Apache, now the 404 is from Kohana:

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

This is my only route in bootstrap.php

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

If I enter an URL without any controller, I can see the default compte Controller, but if I use compte or comptes or whatever, always 404 not found ...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

美胚控场 2025-01-11 23:51:02

关于编辑 3:

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

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

整个内容是可选的,因此它可以匹配空 URI。一旦出现“compte”,“s”也是可选的。一旦您了解了路由,它就会非常强大,您可以此处

Regarding edit 3:

Your route only matches an empty URI string. 'compte' or 'comptes' are not empty strings.
If you want the route to match an empty URI as well as the URIs 'compte' and 'comptes' then use this:

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

The whole thing is optional so it can match an empty URI. The 's' is optional too once 'compte' is present. Routing is very powerfull once you get to know it, which you can here.

欲拥i 2025-01-11 23:51:02

尝试

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

注意 url 部分为空。

Try

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

Note that the url part is empty.

來不及說愛妳 2025-01-11 23:51:02

也许 Apache 未配置为读取 .htaccess 文件。请阅读“404错误”部分:https://github.com/kohana/core/blob/962c5f12714cb3ab146a41db61a888c2b0cc79da/guide/kohana/tutorials/clean-urls.md

Perhaps Apache is not configured to read the .htaccess file. Read the "404 errors" section here: https://github.com/kohana/core/blob/962c5f12714cb3ab146a41db61a888c2b0cc79da/guide/kohana/tutorials/clean-urls.md

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文