首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Kohana URL混淆

Kohana URL混淆
EN

Stack Overflow用户
提问于 2011-04-12 00:50:42
回答 1查看 1.4K关注 0票数 0

我的bootstrap.php文件如下所示,所有代码都嵌入在欢迎控制器->action_index中。

代码语言:javascript
复制
Kohana::init(array(
    'base_url'   => '/kohana/',
    'index' => 'index.php'
));

好的,如果我把下面的内容放在action_index中

代码语言:javascript
复制
form::open('test');

动作是/kohana/index.php/test.

因此,链接似乎是绝对的,您的根安装位置,接受当我嵌入链接在action_index index.php!

代码语言:javascript
复制
html::anchor('controller');

href是/kohana/controller not /kohana/index.php/控制器。

现在如果我把

代码语言:javascript
复制
url::site('controller');

返回的值是/kohana/index.php/controller.

所以我想我可以用

代码语言:javascript
复制
html::anchor(url::site('controller'));

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

世界上发生了什么事,我该怎么解决呢?

Kohana url系统似乎是不直观的,也是错误的。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-04-12 01:05:52

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

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

代码语言:javascript
复制
$uri = URL::site($uri, $protocol, $index);

在这一行中,$index值根据默认的anchor函数值是FALSE

代码语言:javascript
复制
public static function anchor($uri, $title = NULL, array $attributes = NULL, $protocol = NULL, $index = FALSE)

因此,您现在所能做的就是-手动传递第5个参数,就像true一样:

代码语言:javascript
复制
html::anchor('controller', null, null, null, true);

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

代码语言:javascript
复制
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上填充一个bug,让ko决定该做什么。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5629201

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档