1

i have a question about the best practice on urls in a zend application. My application will run in two different contexts (facebook and standalone). Normally my baseUrl is empty. But when run in Facebook (as canvas app) I set my baseUrl to be "apps.facebook.com/xxx"... but there are exceptions. Mostly I want the new baseUrl, but sometimes I do not. Currently I strip out the baseUrl, when I do not need it...

Thanks in advance

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
teebee
  • 43
  • 1
  • 4

2 Answers2

1

You can modify baseUrl in e.g. your view as follows:

<?php 
    // save current base
    $oldBase = $this->getHelper('baseUrl')->getBaseUrl();

    // set a new one for a short time
    echo $this->getHelper('baseUrl')->setBaseUrl('new/base/')->baseUrl('link');

    // restore the original base
    $this->getHelper('baseUrl')->setBaseUrl($oldBase);
?>

It is important to remember to save and restore the original base for the baseUrl. Otherwise, all layout may not work properly as helper 'remember' their state and you don't want to change the base for system wide. Hope this will be helpful.

Marcin
  • 215,873
  • 14
  • 235
  • 294
  • Wouldn't it be better that the application could do this for the programmer? Maybe the application should *remember* about those things :) – takeshin Feb 19 '11 at 13:10
  • thanks for the answer. this is basically one of two things i tried. still verbose.... :( – teebee Feb 24 '11 at 14:48
0

The best choice would be to subclass the BaseUrl view helper and use the extended one when you need the custom value.

takeshin
  • 49,108
  • 32
  • 120
  • 164