开发者

how to sometimes switch baseUrl when calling url view helper

开发者 https://www.devze.com 2023-02-11 05:17 出处:网络
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).

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 baseU开发者_C百科rl, but sometimes I do not. Currently I strip out the baseUrl, when I do not need it...

Thanks in advance


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号