1
votes

Alright, so this is a question more or less questioning how intelligent this design decision was in a symfony project, rather than a question to get something functioning.

A coworker of mine recently decided forms should post certain data on a site using this action:

<form action="http://<?php echo sfConfig::get( 'app_webroot' ) ?>" method="post" name="userCity" id="userCity">

That simply posts a user selected city to the index controller of the site to update the city in the session.

In index.php within the web directory, we have this line:

$configuration = ProjectConfiguration::getApplicationConfiguration('frontend', 'webrootrule', false);

webrootrule being the rule set in app.yml. The purpose is to ensure the forms post to the correct domain, so in my dev environment I have the webroot option in index.php set to my environment, he has his set to his environment, and prod is set to the website's production domain name. Here's what the different webroot paths look like:

echopony.website.internalsite.com
coworker.website.internalsite.com
website.com

I've never needed to do anything like this. Before I divert too much time to getting this working without futzing with index.php and testing all of the forms, I just wanted to bounce this off of some of you and see if this is indeed a waste of our efforts.

Even worse is that index.php is now versioned by him. I do not agree with versioning that file, but rather than outwardly denounce his methods I want to be absolutely sure he's actually doing things wrong. It just seems absurd to have to edit index.php before releasing updates to the site. You know, to avoid index.php setting the webroot as echopony.website.internalsite.com

He has years and years of experience on me, so when I don't agree with his methods... I have to really ensure I'm in the right before taking action.

Thanks for any input!

1

1 Answers

1
votes

You should work with absolute URLS here. Just use the url_for helper of Symfony. This helper is working environment dependend and can generate absolute URLs if you want.

<form action="http://<?php echo url_for('/', true) ;?>" method="post" name="userCity" id="userCity">

the second parameter of the helper is responsible for creating absolute URLs (true) or not (false)

Take a look at the official documentation for more info