Ask your Symfony questions! Pay money and get answers fast! (more info)

How can I generate URLs inside a YAML file? Like url_for()? Symfony

  • SOLVED

Symfony allows me to use PHP to set a value in yaml files. I am curious, is there a way to set a URL? Is there any function like url_for() or gen_url() that would work in app.yml? Failing that, what is the best way for me to get the domain and sub-domain in app.yml?

Answers (3)

2010-07-27

Arturo Linares answers:

First load the helper and then call the function:


<?php
sfLoader::loadHelpers('Url');
?>

all:
test:
url: <?php echo url_for('@homepage') ?>



You can always call the $_SERVER['SERVER_NAME'] to get the information you need for the domain/subdomains.


Lawrence Krubner comments:

Oddly enough, I'm doing this:

urls:
janrain_rpx_login_processing: '<?php echo url_for('user/rpxLogin', true) ?>'


and in the template I call it like this:

<?php echo sfConfig::get('app_urls_janrain_rpx_login_processing') ?>

and I'm getting this:

http://dev.dev.com/dev.phpmodule=user/action=rpxLogin


Any thought why it would mash the URL like that?


Lawrence Krubner comments:

And this:

urls:
janrain_rpx_login_processing: '<?php echo url_for('user/rpxLogin') ?>'


gives me this:


/cao_dev.phpmodule=user/action=rpxLogin


Why? Is there a better function to use than url_for()?


Lawrence Krubner comments:

Actually, I will post all this as a separate question.

2010-07-27

Yura Rodchyn answers:

Arturo Linares is write.
damn he was quick :)

2010-07-27

GlobalOrangeLab answers:

Just load the Url helper in .yml file and you can use 'url_for' anywhere in that .yml file.


<?php sfLoader::loadHelpers('Url'); ?>

all:
test:
url: <?php echo url_for('@homepage') ?>