Possible to modify / write to a custom parameters.yml file in symfony2?

lenny

apologies for the possible n00b question but here we go. I'm currently writing a service class in symfony2 which collects data using ajax. The data basically consists of two timestamps sent upon form submit. What I then want to do is pass this to my controller and write it to a custom parameters.yml file so I can store the values in this file and update this file each time a user submits the form. I am getting an error like this :

Impossible to call set() on a frozen ParameterBag

And some searching on Google tells me that I cannot modify the Container once it has been compiled. The line in particular which is causing this is :

$this->container->setParameter('quicksign.start.off', $startOff);

Okay time to show my code. Here is my controller :

public function updateServiceSigAction() {

$logger = $this->get('logger');
$request = $this->get('request');
$errors = array();

if (WebserviceController::POST_ONLY && $request->getMethod() != 'POST') {
    $errors[] = "Not allowed !";
    return $this->sendResponse($errors);
}

$params = $request->request->all();

if (count($params) == 0) {
    $errors[] = "Missing parameters !";
    return $this->sendResponse($errors);
} else {

    $servicesig_services = $this->get('servicesigservice');
    $errors = $servicesig_services->updateServiceSig($params, false);

}

return $this->sendResponse($errors, array(), true);

}

And here is the relevant method of my service class :

public function updateServiceSig($params, $need_to_flush = true) {

$errors = array();

$startOff = $params['date_debut'];
$endOff = $params['date_fin'];

if (empty($startOff) || empty($endOff)) {
    $errors[] = "Missing parameters from query !";
} else {

    $this->container->setParameter('quicksign.start.off', $startOff);
    $this->container->setParameter('quicksign.end.off', $endOff);
}
return $errors;
}

Maybe I should do this before compiling the container ? But I don't know where exactly the container is being compiled... Or maybe I should do it another way...?

lenny

So here's how I got it done :

use Symfony\Component\Yaml\Dumper; //I'm includng the yml dumper. Then :
$ymlDump = array( 'parameters' => array( 
   'quicksign.active' => 'On', 
   'quicksign.start.off' => $startOff, 
   'quicksign.end.off' => $endOff ), 
 );
$dumper = new Dumper(); 
$yaml = $dumper->dump($ymlDump);
$path = WEB_DIRECTORY . '/../app/config/parameters.sig.yml'; 
file_put_contents($path, $yaml);

Where WEB_DIRECTORY is defined in the app.php file -> however, you should use

%kernel.root_dir%

in the service configuration.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Is it possible to modify a yml file via shell script?

From Dev

Symfony2 get parameters.yml in entity, special case

From Dev

Symfony2: how to read parameters array in config.yml

From Dev

PHPUnit symfony2 faking parameters.yml

From Dev

A parameters.yml per bundle, symfony2

From Dev

PHPUnit symfony2 faking parameters.yml

From Dev

Number index in parameters.yml corrupted Symfony2

From Dev

Translation placeholder in YML format with Symfony2, is possible?

From Dev

Translation placeholder in YML format with Symfony2, is possible?

From Dev

Is it possible to modify parameters of UploadPortletRequest?

From Dev

Difference between parameters.yml and config.yml in Symfony2

From Dev

What's the use of parameters.yml file in Symfony

From Dev

Symfony2 get to the access_control parameters located in the security.yml

From Dev

How can i send parameters to validators.lang.yml in symfony2 validator engine?

From Dev

Symfony2 - where are all the places where the 'secret' key (parameters.yml) is used?

From Dev

Oracle database error in symfony2 (doctrine). Is parameters.yml setup correctly?

From Dev

Loading custom config file for app in symfony2

From Dev

Loading custom config file for app in symfony2

From Dev

Symfony yml parameters into doctrine yml mapping

From Dev

Symfony yml parameters into doctrine yml mapping

From Dev

yml pluralization symfony2

From Dev

Call an .yml file located in app/config from inside a controller Symfony2

From Dev

Call an .yml file located in app/config from inside a controller Symfony2

From Dev

Modify list of parameters in batch file

From Dev

Is it possible to modify an xml file in Terminal?

From Dev

Is it possible to add custom global Symfony2 route variables like _format and _locale?

From Dev

Write automatically in services.yml file

From Dev

Symfony2 Routing parameters

From Dev

Symfony2 predefined parameters

Related Related

  1. 1

    Is it possible to modify a yml file via shell script?

  2. 2

    Symfony2 get parameters.yml in entity, special case

  3. 3

    Symfony2: how to read parameters array in config.yml

  4. 4

    PHPUnit symfony2 faking parameters.yml

  5. 5

    A parameters.yml per bundle, symfony2

  6. 6

    PHPUnit symfony2 faking parameters.yml

  7. 7

    Number index in parameters.yml corrupted Symfony2

  8. 8

    Translation placeholder in YML format with Symfony2, is possible?

  9. 9

    Translation placeholder in YML format with Symfony2, is possible?

  10. 10

    Is it possible to modify parameters of UploadPortletRequest?

  11. 11

    Difference between parameters.yml and config.yml in Symfony2

  12. 12

    What's the use of parameters.yml file in Symfony

  13. 13

    Symfony2 get to the access_control parameters located in the security.yml

  14. 14

    How can i send parameters to validators.lang.yml in symfony2 validator engine?

  15. 15

    Symfony2 - where are all the places where the 'secret' key (parameters.yml) is used?

  16. 16

    Oracle database error in symfony2 (doctrine). Is parameters.yml setup correctly?

  17. 17

    Loading custom config file for app in symfony2

  18. 18

    Loading custom config file for app in symfony2

  19. 19

    Symfony yml parameters into doctrine yml mapping

  20. 20

    Symfony yml parameters into doctrine yml mapping

  21. 21

    yml pluralization symfony2

  22. 22

    Call an .yml file located in app/config from inside a controller Symfony2

  23. 23

    Call an .yml file located in app/config from inside a controller Symfony2

  24. 24

    Modify list of parameters in batch file

  25. 25

    Is it possible to modify an xml file in Terminal?

  26. 26

    Is it possible to add custom global Symfony2 route variables like _format and _locale?

  27. 27

    Write automatically in services.yml file

  28. 28

    Symfony2 Routing parameters

  29. 29

    Symfony2 predefined parameters

HotTag

Archive