June 18, 2007 – 12:15pm Linking between Apps within Symfony

There has been some recent discussion on the symfony mailing list about cross-linking between apps within the same project. I have managed to avoid having to use complex routing rules and instead have gotten away with adding absolute URLS to my app’s settings.yml file, and then using these addresses within my templates.

First, add appropriate URLs in the project’s config/app.yml file. As there are different settings used depending on the environment, you can put the full URL here and have it automatically use the right setting.

prod:
  url:
   frontend:  http://public.mysymfonyapp.com
    backend:   http://private.mysymfonyapp.com
dev:
  url:
   frontend:  http://myappdev/frontend.php
   backend:  http://myappdev/backend.php

Then, in your template, whenever you need to link to the other app, use these settings:

<?php echo link_to('Admin Site', sfConfig::get('app_url_backend')) ?>
or
<?php echo link_to('Public Site', sfConfig::get('app_url_frontend')) ?>
Posted in  Web Development   |     |  delicious  Digg

2 Responses to “Linking between Apps within Symfony”

  1. Is there anything wrong with just redirecting with a relative path from within an action? It seems rather easy.

    $this->redirect(”../otherAppName”)

    I think this works because the native entry file is in the same directory as your index.php file.

    I have just tried it and it seems to work just fine.

    By Tim on Nov 16, 2007

  2. actually, having the directives in the app file for dev vs prod environments is defiantly helpful. I guess i would just define a global app.yml file with the relative file path defined there.

    example:
    prod:
    url:
    corp_home: ../corp.php
    member_home: ../member.php
    guest_home: ../guest.php
    dev:
    url:
    corp_home: ../corp_dev.php
    member_home: ../corp_dev.php
    guest_home: ../guest_dev.php

    By Tim on Nov 16, 2007

Post a Comment

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word