【问题标题】:cakephp route to not allow file extensioncakephp 路由不允许文件扩展名
【发布时间】:2012-03-09 04:14:21
【问题描述】:

我需要一个 cakephp 路由,如果在以前的不包含文件扩展名的路由中不匹配,它将捕获所有 url。

以下全部捕获的当前路线

Router::connect('/*', array('controller' => 'frontend', 'action' => 'display',null));

我需要将上述路由修改为不是所有带有文件扩展名的 url 都会被捕获

【问题讨论】:

    标签: regex cakephp routes cakephp-1.3


    【解决方案1】:

    我在基于 CakePHP 1.2 的应用程序中为动态生成的图像添加扩展的内容如下:

    Router::connect('/postImage/*', array('controller' => 'posts','action' => 'postImage', 'url' => array('ext' => 'png')));
    

    上面的代码使以下网址都可以访问: http://myhost.com/posts/postImage/125http://myhost.com/posts/postImage/125.png

    我认为 CakePHP 1.3 也是如此,希望对您有所帮助。

    【讨论】:

      【解决方案2】:

      我不太了解你的要求,但你可以这样做:

      Router::parseExtensions('html');
      Router::connect('/*/:title', array('controller' => 'frontend', 'action' => 'display',null), 
                    array(
              'pass' => array('title')
            )
      );  
      

      还有链接:

      $html->link('Title', array('controller' => 'frontend', 'action' => 'display', 'title' => Inflector::slug('text to slug', '-'), 'ext' => 'html'))
      

      我希望这会对你有所帮助。祝你好运

      【讨论】:

        猜你喜欢
        • 2019-08-11
        • 2018-04-02
        • 2014-02-09
        • 2017-11-13
        • 1970-01-01
        • 2012-03-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多