我应如何使用Kohana 3将路线操作的连字符更改为下划线? [英] What should I do with Kohana 3 to make route actions' hyphens change to underscores?

查看:66
本文介绍了我应如何使用Kohana 3将路线操作的连字符更改为下划线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

bootstrap.php ...

Route::set('crud', 'staff/<controller>(/<action>(/<id>))', array(
            'controller' => '(activities|users|default-emails)',
            'action' => '(new|view|modify|delete)',
            'id' => '\d+'
    ))->defaults(array(
        'directory' => 'staff',
        'action' => 'view'
    ));

默认电子邮件正在尝试运行 action_default-emails()方法显然不存在,不存在。

The default-emails is trying to run the action_default-emails() method which obviously doesn't and can't exist.

Kohana的哪一部分我应该将连字符内部扩展为下划线吗?

What part of Kohana should I extend to map that hyphen into a underscore internally?

我应该担心的是,如果这样做,可以通过两个 _ 和-分隔的路线?

Should I be concerned that if I do do this, then it will be accessible via both _ and - delimited routes?

谢谢。

推荐答案

最简单的方法是入侵 Kohana_Request :: execute()@ 1112

$class->getMethod('action_'.$action)->invokeArgs($controller, $this->_params);

更改为

$class->getMethod('action_'.str_replace('-', '_', $action))->invokeArgs($controller, $this->_params);

但是您了解,您必须在每个下一个kohana版本中进行此补丁。

But you understand, that you have to do this patch in each next kohana version.

更无害的可能是扩展 Kohana_Route :: matches()

class Route extends Kohana_Route
{
    public function matches($uri)
    {
        $matches = parent::matches($uri);
        if (isset($matches['action']))
        {
            $matches['action'] = str_replace('-', '_', $matches['action'];
        }
        return $matches;
    }
}

没有检查,但我敢打赌它应该起作用。

Did not check, but I bet it should work.

这篇关于我应如何使用Kohana 3将路线操作的连字符更改为下划线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆