Create a gist now

Instantly share code, notes, and snippets.

namespace Acme\DemoBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\HttpFoundation\Request;
use Acme\DemoBundle\Form\Type\SettingsFormType;
class SettingsController extends Controller
{
/**
* The action to manipulate application wide settings
*
* @Route("/settings", name="manage_settings")
* @Template()
*
* @param \Symfony\Component\HttpFoundation\Request $request
*/
public function settingsAction(Request $request)
{
$form = $this->createForm(new SettingsFormType($this->get('settings')));
if ($request->isMethod('POST')) {
$form->bind($request);
if ($form->isValid()) {
$this->get('settings')->setReadOnly(false);
foreach ($form->getViewData() as $key => $data) {
$settingKey = str_replace('_', '.', $key);
$this->get('settings')->set($settingKey, $data);
}
$this->get('settings')->saveToFile();
$this->get('settings')->setReadOnly(true);
$this->get('session')->getFlashBag()->add('success', 'The settings have been saved');
}
}
return array(
'form' => $form->createView()
);
}
}
@bartoszrychlicki

Add an openning <?php tag to enable syntax coloring

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment