0

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 (e.g. myapp.example.com) URL and I want it to output http://app.facebook.com/myapp

Thanks in advance.

Lukas

1
  • I am not sure if did understand it correctly but i guess you are looking to create DNS CNAME Record or as it called alias , so if you did an alias you wouldn't need to change any thing in your ZF app , for example if you create CNAME record of google.com with the name "blahblah.com" , you would be able to browse google.com with that RECORD .
    – tawfekov
    Nov 28, 2010 at 19:36

2 Answers 2

0

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/');
5
  • 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 (e.g. myapp.example.com) URL and I want it to output app.facebook.com/myapp
    – Bery
    Nov 28, 2010 at 17:18
  • Hi,thanks very much - I will post my final code but there another problem has occured. The application now says "Invallid controller specified" and I can not tell why :-(
    – Bery
    Nov 29, 2010 at 10:57
  • Hi, I have been experimenting with the code that you have provided with poor results. The URL is still intact and point to the original server (not the facebook app canvas page). I have also discovered that the setBaseUrl method is (according to the Zedn Api page) used for getting absolute path to the document root than to generate links :-/.
    – Bery
    Dec 2, 2010 at 14:17
  • If you are using the view helper, 'url', to generate your links, it will utilize the baseUrlPath and prepend it to all links generated. Dec 2, 2010 at 16:40
  • Ah, okey. I will give it a try during the weekend and I'll let you know. Thanks for your time.
    – Bery
    Dec 3, 2010 at 12:10
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.