symfony
Doctrine2 $em->persist($entity) on foreach loop
From the Doctrine documentation, it says that inserts are best performed with batch. And its a development of @AlterPHP ‘s answer. You could use : $batchSize = 20; for ($i = 1; $i <= 10000; ++$i) { $car = new Car(); // … set number of wheels, but should always be to 4 right ? … Read more
How to set the exit status code in a Symfony2 command?
In the base Command class: if ($this->code) { $statusCode = call_user_func($this->code, $input, $output); } else { $statusCode = $this->execute($input, $output); } return is_numeric($statusCode) ? (int) $statusCode : 0; So simply return the exit code from your execute() function. Your console command will exit with this code as long as it is a numeric value.
Using Relationships with Multiple Entity Managers
Using different object managers (entity managers) doesn’t allow the object graphs to intersect. That case is too complex and isn’t managed by Doctrine ORM. If you need such a case, keep the object graphs disconnected by saving the identifiers of the related objects (old style) instead of a reference to them, then manually get the … Read more
Access parameter from the Command Class
Simple way, let command extend ContainerAwareCommand $this->getContainer()->getParameter(‘parameter_name’); or You should create seperate service class $service = $this->getContainer()->get(‘less_css_compiler’); //services.yml services: less_css_compiler: class: MyVendor\MyBundle\Service\LessCompiler arguments: [%less_compiler%] In service class, create constructor like above you mentioned public function __construct($less_compiler) { $this->less_compiler = $less_compiler; } Call the service from command class. Thats it. Reason: You are making command class … Read more
Passing variable into included twig template that has variable in template name
I see what I was doing wrong. I had combined two different versions of include, one using {{ and the other using {% due to the symfony and twig docs showing different ways of including templates. This was as simple as removing the parenthesis from my initial code and inserting a with prior to defining … Read more