symfony-2.3

Doctrine partial queries return the complete object

拈花ヽ惹草 提交于 2020-01-04 04:04:46
问题 I'm trying to optimize the query as I need a simple list as an entity that is affiliated with several entities. So I created this query, you should just give me back the id and name: public function findAllOrderByName() { $qb = $this->createQueryBuilder('a'); $query = $qb->select(array('partial a.{id,name}')) ->addOrderBy('a.name', 'ASC') ->getQuery(); return $query->getResult(); } return it in the controller like this: public function getInstrumentsAction() { $instruments = $this-

Load Remote File with TWIG

怎甘沉沦 提交于 2020-01-01 06:25:15
问题 Using Twig in Symfony 2.3 I need to be able to select remote assets inside a twig template. So I have a twig template with a body block like this: {% block body %} {% include 'http://asset.remotelocation.co.uk/template.html.twig' %} {% endblock %} and as you can see its trying to include a remote twig template. Is this possible as symfony just errors saying it cant find the template? The twig template location is correct in my code as I can browse to the template url in my browser. Any help

Call PHP function from Twig template

纵饮孤独 提交于 2019-12-28 06:41:29
问题 I have a function in my controller that returns array of entities so in my twig template I do this to iterate over elements: {% for groupName, entity in items %} <ul> <ul> {% for element in entity %} <li>{{ element.getLabel }}</li> <li><input type="text" name="detail[{{ element.getId }}]" id="pd_{{ element.getId }}" /><input type="text" name="price[{{ element.getId }}]" id="pd_price_{{ element.getId }}" /><input type="text" name="stock[{{ element.getId }}]" id="pd_stock_{{ element.getId }}" /

Inject other parameters to an action when using controllers in classes pattern?

巧了我就是萌 提交于 2019-12-25 01:37:51
问题 I have a class called ApplicationDecorator , which inherits Application and adds some often used methods. At the moment each controller action contains at the beginning a line like $appDec = new ApplicationDecorator($app); Is it possible to tell Silex to pass the instance as parameter to the action like it is done for Application and Request ? So it would look like the following: public function switchAction(ApplicationDecorator $appDec, Request $request) { I am already using Controllers in

How to get data from a form in symfony2

喜夏-厌秋 提交于 2019-12-24 23:18:46
问题 I have a method : public function showCategoryAction($id, $page, Request $request){ $em = $this->getDoctrine()->getManager(); $repositoryProduct = $em->getRepository('ShopDesktopBundle:Product'); $aFilter = array(); $form = $this->get('form.factory')->createNamedBuilder('', 'form', null, array( 'csrf_protection' => false, )) ->setMethod('GET') ->add('minimPrice', 'text', array('mapped' => false, 'label' => 'De la :' , 'attr'=> array( 'placeholder'=>'Minim price', 'class'=>'form-control'))) -

CSS/JS/Images from Bundle location will be always removed after composer.phar update

柔情痞子 提交于 2019-12-24 14:04:42
问题 I have a tiny problem that i don't understand. I have some Bundle project generated by Symfony command, and they create a generic bundle folder in web/bundle/mypersonalbundle. OK, but one of them always be empty when I do an update from composer.phar. And only One! Thanks for your help ! $ php composer.phar update Loading composer repositories with package information Updating dependencies (including require-dev) - Removing doctrine/cache (v1.2.0) - Installing doctrine/cache (v1.3.0) Loading

Symfony 2.3 - Custom Fatal Errors

流过昼夜 提交于 2019-12-24 03:12:29
问题 I've got a problem with Symfony 2.3, I can't get it to work to get a custom function that handles the fatal errors. The Symfony exceptions work fine, like a 404 etc. but a fatal error not. This is what I've got after searching the internet, I've a created a parent controller in the TestBundle. The other default controller extends the TestingSomeThingController. Se the files below for the code. But when I deleted the ; at the end of the line in DefaultController it's shows the standard fatal

Correct way to log from Entities and Repositories in Symfony2

纵然是瞬间 提交于 2019-12-23 09:31:45
问题 What is a way to log messages or errors from an Entity or Repository class in the symfony2 architecture? In symfony1 you could use the singleton to kill puppies by doing something like this to get the logger from anywhere: sfContext::getInstance()->getLogger() Symfony2's container model is stricter, which is great, but how should one go about logging from non-container-aware classes? For repos, I guess you can define them (all) as services, with a dependency on the logger, and go from there.

Form CollectionType with radio buttons fails after Symfony 2.7 upgrade

青春壹個敷衍的年華 提交于 2019-12-23 02:39:31
问题 Getting below error.. An exception has been thrown during the rendering of a template ("The form's view data is expected to be of type scalar, array or an instance of \ArrayAccess, but is an instance of class Proxies__CG__\BLA\MyBundle\Entity\TransportType. You can avoid this error by setting the "data_class" option to "Proxies__CG__\BLA\MyBundle\Entity\TransportType" or by adding a view transformer that transforms an instance of class Proxies__CG__\BLA\MyBundle\Entity\TransportType to scalar

Form CollectionType with radio buttons fails after Symfony 2.7 upgrade

∥☆過路亽.° 提交于 2019-12-23 02:39:11
问题 Getting below error.. An exception has been thrown during the rendering of a template ("The form's view data is expected to be of type scalar, array or an instance of \ArrayAccess, but is an instance of class Proxies__CG__\BLA\MyBundle\Entity\TransportType. You can avoid this error by setting the "data_class" option to "Proxies__CG__\BLA\MyBundle\Entity\TransportType" or by adding a view transformer that transforms an instance of class Proxies__CG__\BLA\MyBundle\Entity\TransportType to scalar