【发布时间】:2014-04-28 08:39:58
【问题描述】:
嗨,我不会用锚点位置渲染视图 - http://example.com/index.php#top
可能是这样的:
$this->render('index', ['data' => $data], 'anchor'=>'top');
有什么想法吗?
【问题讨论】:
-
提问时,请注意正确提问。您的问题很短,充满错误,无法理解您的要求。
嗨,我不会用锚点位置渲染视图 - http://example.com/index.php#top
可能是这样的:
$this->render('index', ['data' => $data], 'anchor'=>'top');
有什么想法吗?
【问题讨论】:
当您调用render 时,URL 已经设置,因为您在controller(或view)中。所以这个时候不能给url添加锚点。
您必须在调用控制器之前设置锚点。要做到这一点,您可以在创建 url 时设置锚点:
$this->createUrl('controller/action', array('#' => 'the-anchor'));
您还可以使用redirect 将访问者重定向到带有锚点的页面
$this->redirect(array('controller/action', array('#' => 'the-anchor')));
但我认为在创建 url 时设置锚点是实现您想要的最佳方式。
【讨论】: