简体   繁体   English

Zend框架Facebook重定向URL到画布应用程序URL

[英]Zend framework facebook redirect URL to canvas application URL

I am currently developing a facebook canvas (iframe) based application. 我目前正在开发一个基于facebook canvas(iframe)的应用程序。 Is there any way to get Zend framework to output URLs like this: 有什么办法可以使Zend框架输出如下URL:

http://app.facebook.com/appName/controller/action

intead of getting 获得兴趣

http://www.domain.com/controller/action ?

It is not so important because due to iframe based app everything is working fine, but I'd like to provide better user experince and getting the url 并不是很重要,因为由于基于iframe的应用程序一切正常,但是我想提供更好的用户体验并获取url

http://app.facebook.com/appName/ 

is not user friendly at all. 根本不是用户友好的。 Probably the solution is very easy but I am completely "stack". 解决方案可能很简单,但我完全是“堆栈”。 The application is devided to modules so I can change sth in Boostrap.php which is probably to hold the solution underneath my nose but I can not see it..:-/ 该应用程序是按模块划分的,因此我可以在Boostrap.php中更改某项内容,该内容可能将解决方案保留在我的鼻子下面,但我看不到它..:-/

EDIT: Maybe i did not expressed it as I should have. 编辑:也许我没有像我应该的那样表达它。 The problem is not within facebook. 问题不在Facebook内。 The problem is in zend itself . 问题在于zend本身 It outputs the original application (eg myapp.example.com) URL and I want it to output http://app.facebook.com/myapp 它输出原始应用程序 (例如myapp.example.com)URL,我希望它输出http://app.facebook.com/myapp

Thanks in advance. 提前致谢。

Lukas 卢卡斯

I'm not sure what your question is but Facebook already maps the URLs it receives to your application. 我不确定您的问题是什么,但是Facebook已经将收到的URL映射到您的应用程序。

For example if your canvas URL is set to http://domain.com/ and a user goes into http://apps.facebook.com/appName/controller it will get mapped to http://domain.com/controller by Facebook. 例如,如果您的画布URL设置为http://domain.com/并且用户进入http://apps.facebook.com/appName/controller则它将通过以下方式映射到http://domain.com/controller :脸书

It works this way for both canvas/fbml and iframe applications. 它适用于canvas / fbml和iframe应用程序。

To make Zend Framework generate URLs with an alternate base (ie: http://apps.facebook.com/appName ) you can do this in your bootstrap: 要使Zend Framework生成具有备用基址的URL(即: http://apps.facebook.com/appName : http://apps.facebook.com/appName ),可以在引导程序中执行以下操作:

protected function _initBaseUrl() {        
    $front  = $this->getResource('frontcontroller');
    $front->setBaseUrl('http://apps.facebook.com/appName/');
}

If you are not using the bootstrap, you can get an instance of your front controller in an alternate way and do this: 如果您不使用引导程序,则可以通过其他方式获取前端控制器的实例,然后执行以下操作:

    $front  = Zend_Controller_Front::getInstance();
    $front->setBaseUrl('http://apps.facebook.com/appName/');

Finally, I managed to solve this issue. 最后,我设法解决了这个问题。 So for fellow developers I am posting here my solution. 因此,对于其他开发人员,我将在此处发布我的解决方案。

The soulition is to be honest a bit complicated but: 老实说,灵魂的归属有点复杂,但是:

Use Zend_Controller_Router_Route_Hostname

The example of usage can be found in http://framework.zend.com/manual/en/zend.controller.router.html the and then Chain it with classic route like: 使用示例可在http://framework.zend.com/manual/en/zend.controller.router.html中找到,然后使用经典路由将其链接,例如:

$hostnameRoute = new
    Zend_Controller_Router_Route_Hostname(
                     ':username.users.example.com',
                     array(       
                  'controller' => 'profile',
                  'action'     => 'userinfo'
              )
      );
$plainPathRoute = new Zend_Controller_Router_Route_Static('');
$router->addRoute('user', $hostnameRoute->chain($plainPathRoute);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM