I've done it before, with a custom route class, a bit like this:
<?php
class sfDoctrineMultiRoot extends sfRequestRoute {
public function matchesUrl($url, $context = array()) {
if (false === $parameters = parent::matchesUrl($url, $context)) {
return false;
}
$company = Doctrine_Core::getTable('Company')
->find($parameters['company_id']);
if (!$company) {
return false;
}
$blog = Doctrine_Core::getTable('Blog')
->find($parameters['blog_id']);
if (!$blog) {
return false;
}
$this->company = $company;
$this->blog = $blog;
return $parameters;
}
public function getCompany() {
return $this->company;
}
public function getBlog() {
return $this->blog;
}
public function generate($params, $context = array(), $absolute = false)
{
foreach ($params as $key=>$param) {
if (method_exists($param, 'getRawValue')) {
$params[$key] = $param->getRawValue();
}
}
if (isset($params['company']) && $params['company'] instanceof Company) {
$params['company_id'] = $params['company']->getId();
}
unset($params['company']);
if (isset($params['blog']) && $params['blog'] instanceof Blog) {
$params['blog_id'] = $params['blog']->getId();
unset($params['blog']);
}
unset($params['blog']);
return parent::generate($params, $context, $absolute);
}
}
You have to use something like this in routing.yml:
test:
url: /company/:company_id//blog/:blog_id
class: sfDoctrineMultiRoot
param: { module: company, action: show }
You can generate urls via url_for and link_to like this:
url_for('test', array('blog'=>BlogObject, 'company'=>'CompanyObject'));
or
url_for('test', array('blog_id'=>1, 'company_id'=>2));
And to retrieve the objects in your action you can call:
$this->getRoute()->getBlog();
or
$this->getRoute()->getCompany();