SUBSCRIBE VIA RSS


Subscribe to our feed

Symfony Experts

Symfony Experts
If you have an urgent question for a symfony-related issue, this is the place to ask.

Topics

Stack Overflow


The old fashioned way

RECENT TUNES

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 by in  Web Development   |  

4 Responses to Linking between Apps within Symfony

  1. Tim says:

    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.

  2. Tim says:

    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

  3. Wiggins says:

    I do something very similar to this but i use this function in my LocalSettings as well

    public static function frontend_url($url_part)
    {
    $proto = sfConfig::get(‘app_frontend_proto’,’http’);
    $host = sfConfig::get(‘app_frontend_host’);
    if ($url_part[0] != ‘/’) $url_part = ‘/’.$url_part;
    return $proto.’://’.$host.$url_part;
    }

    Then in templates you get the convience of doing such:

    getId())?>

  4. Wiggins says:

    heh the convience of doing:

    <?= link_to(“Post”,LocalSettings::frontend_url(‘post/view/id/’.$post->getId()))?>