【问题标题】:Kohana 3.3 Routing IssueKohana 3.3 路由问题
【发布时间】:2013-09-12 00:14:33
【问题描述】:

我使用的这条路线在本地 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]

我是否遗漏了一些明显的东西?路由总是让我很伤心……/恼火

【问题讨论】:

    标签: .htaccess routes kohana


    【解决方案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 正在寻找与 URI panel/asset/warranty/edit 匹配的路由,我认为这就是您想要的。所以问题可能出在您的应用程序中,而不是 .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。当我从您的问题中复制班级名称并用它替换我自己输入的班级名称时,它突然起作用了。如果我解开粘贴,它会再次停止工作。我逐信检查,我的编辑在前后向我展示了完全相同的内容。

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

    【讨论】:

    • 是的,我在保修文件中进行了各种调试,但没有运气。如果我在 execute_request() 中回显 $prefix。它向我显示“Controller_Panel_asset_”。一些“资产”是如何小写的。”我在写这篇文章时仍在研究这个。
    • 我只是在 execute_request() 中加入了一个小技巧。在 $directory 中检查“/”。如果是这样,请分解,将数组中的每个都大写,然后将它们全部放回原处。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-04-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-04
    • 1970-01-01
    相关资源
    最近更新 更多