【问题标题】:How send anchor to URL with render() Yii [closed]如何使用 render() Yii 将锚点发送到 URL [关闭]
【发布时间】:2014-04-28 08:39:58
【问题描述】:

嗨,我不会用锚点位置渲染视图 - http://example.com/index.php#top

可能是这样的:

$this->render('index', ['data' => $data], 'anchor'=>'top');

有什么想法吗?

【问题讨论】:

  • 提问时,请注意正确提问。您的问题很短,充满错误,无法理解您的要求。

标签: html yii anchor


【解决方案1】:

当您调用render 时,URL 已经设置,因为您在controller(或view)中。所以这个时候不能给url添加锚点。

您必须在调用控制器之前设置锚点。要做到这一点,您可以在创建 url 时设置锚点:

$this->createUrl('controller/action', array('#' => 'the-anchor'));

您还可以使用redirect 将访问者重定向到带有锚点的页面

$this->redirect(array('controller/action', array('#' => 'the-anchor')));

但我认为在创建 url 时设置锚点是实现您想要的最佳方式。

【讨论】:

    猜你喜欢
    • 2021-05-11
    • 1970-01-01
    • 2020-07-19
    • 1970-01-01
    • 2011-03-05
    • 1970-01-01
    • 1970-01-01
    • 2010-11-20
    • 2013-05-16
    相关资源
    最近更新 更多