【问题标题】:Kohana URL ConfusionKohana URL 混淆
【发布时间】:2011-04-12 00:50:42
【问题描述】:

我的 bootstrap.php 文件长这样,所有代码都嵌入到welcome controller->action_index中。

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

好的,如果我将以下内容放入 action_index 中

form::open('test');

动作是/kohana/index.php/test
所以链接似乎是你的根安装位置的绝对链接,当我在 action_index index.php 中嵌入链接时接受!!!

html::anchor('controller');

href 是 /kohana/controller 而不是 /kohana/index.php/controller

现在如果我放

url::site('controller');

返回值为/kohana/index.php/controller

所以我想我会使用

html::anchor(url::site('controller'));

但 href 现在等于 http://localhost/kohana/kohana/index.php/controller

到底发生了什么,我该如何解决?

Kohana url 系统似乎很不直观且错误。

【问题讨论】:

  • 你需要 index.php 还是可以不用?
  • 我在安装了 apache 和 mysql 的 ubuntu 上。在我的服务器上我有 htacess 但在 localhost 上没有。如果没有 htaccess,我无法进行 url 重写,但我可以安装它。
  • 将行更改为'index' => false 以使其完全一样
  • 做什么都一样?要删除 index.php,我需要 htaccess

标签: kohana kohana-3


【解决方案1】:

似乎这是HTML::anchor 实现中的某种错误。

这是因为html.php (v3.1.2) 的第 127 行

$uri = URL::site($uri, $protocol, $index);

根据默认的anchor函数值,这行$index的值为FALSE

public static function anchor($uri, $title = NULL, array $attributes = NULL, $protocol = NULL, $index = FALSE)

所以你现在所能做的就是 - 手动将第 5 个参数作为 true 传递,例如:

html::anchor('controller', null, null, null, true);

或使用自定义类扩展Kohana_HTML,例如:

class HTML extends Kohana_HTML
{
    public static function anchor($uri, $title = NULL, array $attributes = NULL, $protocol = NULL, $index = TRUE)
    {
        return parent::anchor($uri, $title, $attributes, $protocol, $index);
    }
}

或填补kohana bugtracker 上的错误,以便开发团队决定要做什么。

【讨论】:

  • 如果未指定,则应读取配置设置。我认为这是一个错误。
  • @pedro_sland:确实如此。但作为临时解决方案,我们可以使用扩展 hack ;-)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-02-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-01-06
  • 2016-09-17
相关资源
最近更新 更多