Hi all,
I am facing a (little) problem and need some advice on the following matter:
1. Prerequesite
we have a symfony environment (1.0.5) with different applications. There is an internal project management (different PROJECT_* tables) and all applications should be accessible by the user through the following url structure:
http://mydomain.com/<project_unique_tag>/<application_tag>/<action_module_whatever>
e.g.
if we have two applications, one ist called frontend another one backend and we want them called by the user for the project with the unique tag XYZ, the urls should look like this:
http://mydomain.com/XYZ/frontend/en/home.html
http://mydomain.com/XYZ/backend/home.html
for another project called 123 the urls should look like:
http://mydomain.com/123/frontend/en/home.html
http://mydomain.com/123/backend/home.html
2. Setup
That's the goal and this is my first approach on how to handle it:
All controllers for the different applications reside under the web/ folder and are accessible by the following rewrite rules in the .httaccess file:
RewriteRule ^(.*)/frontend/(.*)$ frontend.php [QSA,L]
RewriteRule ^(.*)/backend/(.*)$ backend.php [QSA,L]
# no, so we redirect to our front web controller
RewriteRule ^(.*)$ index.php [QSA,L]
Now, I have the problem, that the different applications need the <project_unique_tag>, so I thought I add them every route of the different applicatsion:
1. routing.yml for frontend:
e.g.
...
sf_guard_signin:
url: /:project/frontend/:sf_culture/login.html
requirements: { sf_culture: (?:en|de) }
param: { module: sfGuardAuth, action: signin }
...
2. routing.yml for backend:
e.g.
...
sf_guard_signin:
url: /:project/backend/:sf_culture/login.html
requirements: { sf_culture: (?:en|de) }
param: { module: sfGuardAuth, action: signin }
...
3. Problem
That's the setup and now to the problem. As we need the <project_unique_tag> in every action we don't want to assign the paramter every time we set up a link or call a route. So I am looking for a way to set the project string (e.g. XYZ, 123) as default for every route. Capter 9 in the Symfony book [1] describes how to set a default value, so I thought I could easily integrate it using a custom filter and checking for the first request param (<project_unique_tag>), but that did not really work.
Example of a custom filter setting the project param to a static value:
class myProjectFilter extends sfFilter
{
public function execute($filterChain)
{
// Execute this filter only once
if ($this->isFirstCall())
{
sfConfig::set('sf_routing_defaults', array('project' => '123'));
// Execute next filter
$filterChain->execute();
}
}
}
I get the following error, though I haven't even tried to set the project param dynamically:
Route named "sf_guard_signin" have a mandatory "sf_culture" parameter
So now I am stuck and hope for some good advice on how to handle this matter. Thank's in advance!
Regards
Patrick
[1] http://www.symfony-project.com/book/trunk/09-Links-and-the-R outing-System#Setting%20Default%20Values