【问题标题】:How to redirect in CakePHP with # in url, and not %23?如何在 CakePHP 中使用 url 中的 # 而不是 %23 进行重定向?
【发布时间】:2013-05-24 12:09:01
【问题描述】:

我正在使用 CakePHP,我正在这样做:

$this->redirect(array('controller' => 'users', 'action' => 'view',$id));

在浏览器中输出:.../users/view/42

由于我使用的是 JQueryUI 选项卡,我希望用户被重定向到他刚刚编辑的选项卡,所以它应该看起来像:

 $this->redirect(array('controller' => 'users', 'action' => 'view',$id."#groups"));

浏览器中的输出:.../users/view/42%23groups

但预期结果:.../users/view/42#groups

问:如何发送正确的带有#id的url来发送焦点?

如果可能的话,我希望不要使用在 view.ctp 中回显 js 的自定义 GET 参数来获取焦点。

我希望这是一个 CakePHP 问题,不需要像 (How to rewrite a URL with %23 in it?) 那样更改一些 .htaccess 文件

【问题讨论】:

    标签: cakephp redirect


    【解决方案1】:

    这就是我实现它的方式:

    // Redirect to the home page.
    $this->redirect(array(
        'controller' => 'cars',
        'action' => 'index',
        '#' => 'thankyou'
    ));
    

    【讨论】:

      【解决方案2】:

      请阅读文档 http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::url

      $this->redirect(array(
          'controller' => 'users', 'action' => 'view', $id, '#' => 'groups'));
      

      【讨论】:

      • 刚刚发布了这个 Q,我在 stackoverflow.com/questions/8615516/… 找到了遮阳篷,在我的例子中是: $this->redirect(array('controller' => 'users', 'action' = > 'view',$id,'#' =>"groups")); (我在建议的问题标题中搜索“#”,而不是“hashtag”,但我没有足够的声誉来解决我自己的问题...
      • 正如上面已经提到的,您会在阅读官方文档时找到答案。
      • 我已经固定了 cakephp doc 标签,但是不知道为什么这次我先在网上搜索却没有找到;我来了。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-19
      • 2014-08-30
      • 1970-01-01
      • 1970-01-01
      • 2016-08-19
      相关资源
      最近更新 更多