0

我使用的这条路线在本地 MAMP 服务器上运行良好,但在 Dreamhost 或 HostPapa 上运行良好。我认为这只是区分大小写的问题,但据我所知,一切看起来都很好。

错误信息

Kohana_HTTP_Exception [ 404 ]: The requested URL panel/asset/warranty/edit was not found on this server.

路线:

Route::set('panel/asset', '<directory>(/<controller>(/<action>(/<id>)))',
    array(
        'directory' => 'panel/asset',
        'controller' => 'warranty',
    ))
    ->defaults(array(
        'action' => 'edit',
    ));

控制器:控制器/面板/资产/Warranty.php

class Controller_Panel_Asset_Warranty extends Controller_Site_AdminTemplate

.htaccess

# Turn on URL rewriting
RewriteEngine On
Options -MultiViews
# Installation directory
RewriteBase /

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

SetEnv KOHANA_ENV DEVELOPMENT

# 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

# Required for dreamhost
RewriteCond $1 !^(index\.php|public|user_guide|robots\.txt)

RewriteRule .* index.php?$0 [PT,L,QSA]

我错过了一些明显的东西吗?路由总是让我如此悲痛……/恼火

4

1 回答 1

1

如果您希望参数是硬编码字符串,请不要将其放入正则表达式数组中。仅当您在值中实际使用某些正则表达式功能时才使用正则表达式数组。

这会更好。您可以使用正则表达式数组来确保 id 是数字,这是使用它的正当理由。

Route::set('panel/asset', 'panel/asset(/warranty(/<action>(/<id>)))')
    ->defaults(array(
        'directory' => 'panel/asset',
        'controller' => 'warranty',
        'action' => 'edit',
    ));

但是,如果 URI 与异常读取的路由不匹配,这不会帮助您解决手头的问题Kohana_HTTP_Exception [ 404 ]:Unable to find a route to match the URI: panel/asset/warranty/edit.

例外是告诉您 Kohana 正在寻找与panel/asset/warranty/edit我认为您想要的 URI 匹配的路由。所以问题可能出在您的应用程序中,而不是 .htaccess 文件中。

只有两种方法包含以下代码块。

throw HTTP_Exception::factory(404,
    'The requested URL :uri was not found on this server.',
    array(':uri' => $this->request->uri())
)->request($this->request);

这些方法是Request_Client_Internal::execute_request()Controller::execute()

您是否放置了某种调试语句Controller/Panel/Asset/Warranty.php以查看是否找到并执行了它?因为在复制时,我以某种方式执行了文件,但 class_exists('Controller_Panel_Asset_Warranty', FALSE) 返回了 FALSE。当我从您的问题中复制班级名称并用它替换我自己输入的班级名称时,它突然起作用了。如果我解开粘贴,它会再次停止工作。我逐信检查,我的编辑在之前和之后向我展示了完全相同的内容。

我希望这可以帮助您缩小范围。

于 2013-09-12T09:38:48.630 回答