symfony-2.3

Symfony2.3 Better way to get EntityManager inside a Controller

扶醉桌前 提交于 2019-12-05 10:27:25
I'm using Symfony2.3 and I currently using EntityManager as shown inside __construct() Which its a better aproach using EntityManager from __construct() or using inside each method ? as shown in public indexAction() /** * QuazBar controller. * */ class QuazBarController extends Controller { public function __construct() { $this->em = $GLOBALS['kernel']->getContainer()->get('doctrine')->getManager(); } /** * Lists all QuazBar entities. * */ public function indexAction(Request $request) { $session = $request->getSession(); $pagina = $request->query->get('page', 1); $em = $this->getDoctrine()-

How do I get Symfony forms to work with a REST API?

↘锁芯ラ 提交于 2019-12-05 07:32:00
I'm currently trying to get symfony forms to work with my post and put rest api endpoint. Currently I have: $request = $this->getRequest(); $cc = new CreditCard(); $form = $this->createForm(new CreditCardType(), $cc); $form->handleRequest($request); if ($form->isValid()) { //... } However, the form is never valid. Looking into the problem, it seems that the form's isSubmitted field is false, so it never passes validation. Also, since this is an api call, I have the csrf_protection set to false in the creditcardtype. Here is an example of what data I'm having the user submit: { "credit_card": {

How to log in User in Session within a Functional Test in Symfony 2.3?

大兔子大兔子 提交于 2019-12-05 00:06:01
问题 I have read many posts on stackoverflow about this. But most of the methods not useful in Symfony 2.3. So I have try to log in user manually in test to make some actions in back-end. Here is my security.yml security: ... role_hierarchy: ROLE_SILVER: [ROLE_BRONZE] ROLE_GOLD: [ROLE_BRONZE, ROLE_SILVER] ROLE_PLATINUM: [ROLE_BRONZE, ROLE_SILVER, ROLE_GOLD] ROLE_ADMIN: [ROLE_BRONZE, ROLE_SILVER, ROLE_GOLD, ROLE_PLATINUM, ROLE_ALLOWED_TO_SWITCH] providers: database: entity: { class: Fox

Symfony HttpFoundation UploadedFile “not uploaded due to unknown error” when using Doctrine DataFixtures

浪子不回头ぞ 提交于 2019-12-04 09:53:50
I've been using my Attachment entity based on the cookbook recipie How To Handle File Uploads With Doctrine in Symfony 2.3. It works well, even in functional tests. However using it with Doctrine DataFixtures is causing me problems. [Symfony\Component\HttpFoundation\File\Exception\FileException] The file "o-rly-copy.jpg" was not uploaded due to an unknown error. This was not helpful, however I did run php app/console doctrine:fixtures:load -v to bring up a stack trace and it appears the exception is thrown not on the persisting method, but on $manager->flush() Attachment::setFile() requires an

ElasticSearch RoutingMissingException

本秂侑毒 提交于 2019-12-04 01:40:27
I'm trying to populate objects having parent-child relation, but get an error: [Elastica\Exception\ResponseException] RoutingMissingException[routing is required for [myindex]/[comment]/[12345]] Excerpt from type conf: article: _source: enabled: false mappings: ... comment: _source: enabled: false _parent: type: article property: article_id identifier: id _routing: required: true path: article_id mappings: article: type: long index: not_analyzed ... Cant understand what I am missing here.... I'm using Symfony2.3, FOSElasticaBundle 3.0, ElasticSearch 1.2.2 When you have a parent child

Composer: how to install `dev` packages in Symfony 2.3?

心不动则不痛 提交于 2019-12-03 19:28:27
问题 Trying to install the KnpGaufretteBundle in a Symfony 2.3 project, I'm having no luck. The problem is: minimum-stability:stable (in composer.json ); the bundle I require is dev-master version still. Reading this in the Symfony docs was frustrating: If you know of a cool bundle or PHP library that still requires a dev minimum stability, talk to the lead developer and convince him to tag a stable release. I'm not changing the minimum stability of the whole project to dev , as it would certainly

Symfony2 -> Twig -> Form -> Field -> Set rendered = true

怎甘沉沦 提交于 2019-12-03 16:07:05
问题 i have a simple problem. I have a form with a field for example: $builder ->add('x') ->add('y') ->add('z') ; In my twig files i used multiple blocks and i want to stop render fields... I view the b.html.twig file! a.html.twig {% block body %} {% block form %} {{ form_widget(form) }} {% endblock form %} {% endblock body %} b.html.twig {% block form %} {{ form.x.set('rendered', true) | default() }} {{ parent() }} {% endblock form %} If i remove the "default()" i get the error, that the object

How to log in User in Session within a Functional Test in Symfony 2.3?

心不动则不痛 提交于 2019-12-03 16:03:20
I have read many posts on stackoverflow about this. But most of the methods not useful in Symfony 2.3. So I have try to log in user manually in test to make some actions in back-end. Here is my security.yml security: ... role_hierarchy: ROLE_SILVER: [ROLE_BRONZE] ROLE_GOLD: [ROLE_BRONZE, ROLE_SILVER] ROLE_PLATINUM: [ROLE_BRONZE, ROLE_SILVER, ROLE_GOLD] ROLE_ADMIN: [ROLE_BRONZE, ROLE_SILVER, ROLE_GOLD, ROLE_PLATINUM, ROLE_ALLOWED_TO_SWITCH] providers: database: entity: { class: Fox\PersonBundle\Entity\Person, property: username } firewalls: dev: pattern: ^/(_(profiler|wdt)|css|images|js)/

How to change form field value in symfony 2

馋奶兔 提交于 2019-12-03 10:49:27
I have a form like below: class ItemType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) { $builder // ... ->add('tags','text',array( 'required' => false, 'attr' => array('name' => 'tags'), 'mapped' => false)) ; } public function setDefaultOptions(OptionsResolverInterface $resolver) { $resolver->setDefaults(array( 'data_class' => 'MyBundle\ItemBundle\Entity\Item', 'cascade_validation' => true, )); } } My edit action public function editAction(Request $request, $id) { $em = $this->getDoctrine()->getManager(); $entity = $em->getRepository(

Symfony2 - form_start function customise in twig

半腔热情 提交于 2019-12-03 10:45:58
问题 Form helpers form_start and form_end are useful in twig: {{ form_start(form) }} {{ form_end(form) }} I can customise some parameters like the method or the action . But I need to customise others parameters like the class or add the form-enctype . Can I do it? Should i set up it into the FormType.php ? Since now I simply try to add my customised value to the twig function like below: {{ form_start(form, {'class': 'myclass', 'action': 'myaction'}) }} // fields... {{ form_end(form, {'render