Dor*_*ron 3 url model-view-controller zend-framework
我有一个facebook应用程序.
Facebook说我需要重定向到某个facebook网址,以便用户授予应用程序权限.
我目前有一个视图phtml文件,以下工作正常:
<script type="text/javascript">
top.location.href = 'https://www.facebook.com/dialog/oauth?client_id=<?php echo $this->fbAppId?>&redirect_uri=<?php echo $this->serverUrl() . $this->baseUrl() . $this->url(array('controller' => 'index', 'action' => 'post-authorize'))?>&scope=publish_stream,user_birthday,user_about_me,user_activities,user_location';
</script>
Run Code Online (Sandbox Code Playgroud)
但是 - 我想尝试一种不同的方法,通过不渲染视图来节省资源和处理时间,只需通过Location头重定向(使用重定向器动作助手或任何其他动作帮助器).
在视图脚本中,我使用ServerUrl视图助手来生成绝对路径.
如何在不使用视图助手的情况下在控制器中生成绝对路径?
我不知道如何在MVC模式中使用控制器内的视图助手是一个很好的做法.
注意:重定向到facebook,我自己的网站url作为get参数附加.所以我需要的绝对网址是我自己而不是facebook.这意味着使用该setUseAbsoluteUri方法对我没用,因为它可以在facebook url上运行,而不是我的.
在控制器操作中使用视图助手不会呈现视图.
$redirectUri = $this->view->serverUrl() . $this->view->baseUrl() . $this->view->url(array('controller' => 'index', 'action' => 'post-authorize'))
$fbUrl = 'https://www.facebook.com/dialog/oauth?client_id='.$this->fbAppId.'&redirect_uri='.$redirectUri.'&scope=publish_stream,user_birthday,user_about_me,user_activities,user_location';
$this->_redirect($fbUrl);
Run Code Online (Sandbox Code Playgroud)
在调用操作之前,无论如何都会在控制器中初始化View对象(而不是脚本).
| 归档时间: |
|
| 查看次数: |
5704 次 |
| 最近记录: |