简体   繁体   中英

Zend framework facebook redirect URL to canvas application URL

I am currently developing a facebook canvas (iframe) based application. Is there any way to get Zend framework to output URLs like this:

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

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..:-/

EDIT: Maybe i did not expressed it as I should have. The problem is not within facebook. The problem is in zend itself . It outputs the original application (eg myapp.example.com) URL and I want it to output 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.

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.

It works this way for both canvas/fbml and iframe applications.

To make Zend Framework generate URLs with an alternate base (ie: http://apps.facebook.com/appName ) you can do this in your bootstrap:

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:

$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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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