Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

url_for in backend for frontend - Symfony

i made in frontend nice url with symfony routing.yml. In frontend i can use for example:

url_for('@news', $news);

this generate for me:

http://mysite.com/frontend_dev.php/news/nice-title/1

but if i use this in backend i have:

http://mysite.com/backend_dev.php/news/nice-title/1

is possible generate these link in backend for frontend?

like image 480
Olly Vitts Avatar asked Dec 19 '11 02:12

Olly Vitts


1 Answers

In apps/frontend/config/frontendConfiguration.class.php use something like this:

class frontendConfiguration extends sfApplicationConfiguration
{
  protected $backendRouting = null;

  public function generateBackendUrl($name, $parameters = array(), $absolute = false)
  {
    return sfConfig::get('app_site_url').$this->getBackendRouting()->generate($name, $parameters, $absolute);
  }

  public function getBackendRouting()
  {
    if (!$this->backendRouting )
    {
      $this->backendRouting = new sfPatternRouting(new sfEventDispatcher());

      $config = new sfRoutingConfigHandler();
      $routes = $config->evaluate(array(sfConfig::get('sf_apps_dir').'/backend/config/routing.yml'));

      $this->backendRouting->setRoutes($routes);
    }

    return $this->backendRouting;
  }
}

use it like this:

$sf_context->getConfiguration()->generateBackendUrl('my_custom_route', array('id' => 1), true)

More information here: http://symfony.com/blog/cross-application-links

like image 140
Vlad Jula-Nedelcu Avatar answered Sep 29 '22 13:09

Vlad Jula-Nedelcu