symfony-2.1

Updating (from the inverse side) bidirectional many-to-many relationships in Doctrine 2?

試著忘記壹切 提交于 2019-12-03 08:10:30
Customer is the inverse side of "keywords/customers" relationship with Keyword : /** * @ORM\ManyToMany(targetEntity="Keyword", mappedBy="customers", * cascade={"persist", "remove"} * ) */ protected $keywords; When creating a new customer, one should select one or more keywords. The entity form field is: $form->add($this->factory->createNamed('entity', 'keywords', null, array( 'class' => 'Acme\HelloBundle\Entity\Keyword', 'property' => 'select_label', 'multiple' => true, 'expanded' => true, ))); In my controller code, after binding the request and check if form is valid, I need to persist both

How to add an autocomplete field in a Symfony2 form for a collection and using Propel?

£可爱£侵袭症+ 提交于 2019-12-03 07:36:24
问题 I'm using Symfony 2.1 forms with PropelBundle and I'm trying to refactor a form that had a drop-down list of objects (to select from) to instead use a jquery autocomplete field (working with AJAX). For the dropdown list I was using the following code (which worked perfectly for the drop-down) in my form type: $builder->add('books', 'collection', array( 'type' => 'model', 'options' => array( 'class' => 'MyVendor\MyBundle\Model\Book', 'property' => 'title', ), 'allow_add' => true, 'allow_delete

Symfony2 global and optional locale detection from route

亡梦爱人 提交于 2019-12-03 05:55:23
问题 Here's what I want to achieve, followed by a compilation of the knowledge I acquired, with no solution. In a Symfony2 project, without using a dedicated bundle , I want the first directory in path to define the locale. It must be optional: 1. http://www.example.com/user/account => default EN locale, user bundle, account controller, default index action. 2. http://www.example.com/fr/user/account => forced FR locale... 3. http://www.example.com/en/user/account => forced EN locale (needed option

Manually change or catch the message for invalid CSRF token in Symfony2.1

让人想犯罪 __ 提交于 2019-12-03 04:00:00
I'm using Symfony2.1 . It has a builtin CSRF protection for the forms. The error message returned when the CSRF token is invalid is: " The CSRF token is invalid. Please try to resubmit the form ". I show it on the top of the form in my Twig template by using the classic call: {{ form_errors(form) }} How can I change the returned message? In alternative, a more advanced possibility is to catch this error type in order to show a lot of options/links in my Twig template. Any idea? Did you try to set in the file validators.{locale_code}.yml to set a translation for key The CSRF token is invalid.

Symfony 2 - How to delete a bundle?

烂漫一生 提交于 2019-12-03 03:36:11
问题 So my question is how to delete bundle I created? You create bundles with this console command: php app/console generate:bundle --namespace=Test/BlogBundle --format=yml And thats awsome but what if I need to delete this bundle? Is there a console command to delete a bundle I dont need any more? I know that when you create new bundle from console, you: 1. create /src/Test/BlogBundle directory 2. change /app/config/routing.yml file to include routes 3. include your new bundle in /app/Resources

Mixing route and query parameters using FOSRestBundle with Symfony

淺唱寂寞╮ 提交于 2019-12-03 03:15:55
Using Symfony2 and FOSRestBundle I am attempting to implement API methods that have some number of fixed parameters defined in the route along with some optional parameters that may exist in the query string. For example: http://somesite.com/api/method/a/b http://somesite.com/api/method/c/d?x=1&y=2 According to the documentation for FOSRestBundle , ParamFetcher is the proper way to do this, using the @QueryParam annotation. However, I already have a controller defined like: use Symfony\Bundle\FrameworkBundle\Controller\Controller; use FOS\RestBundle\Controller\Annotations\Get; use FOS

How do I force doctrine to reload the data from the database?

送分小仙女□ 提交于 2019-12-03 01:02:06
I'm using doctrine/mongodb 1.0.0-BETA1 in a symfony2.1 install. So i'm trying to force my repository to call data from my database instead of using the object it has cached. $audit = $dm->getRepository("WGenSimschoolsBundle:Audit")->findOneById("xxxx"); .... do something somewhere to change the object .... At this point if I call $audit = $dm->getRepository("WGenSimschoolsBundle:Audit")->findOneById("xxxx"); The audit data hasn't changed. It still has the object it originally fetched. If I try to $dm->refresh($audit) I get the same thing. Is there anyway for me to go back to the database for

Where to register autoload when the vendor is not managed with composer in Symfony 2.1?

£可爱£侵袭症+ 提交于 2019-12-02 23:10:58
I'm using symfony 2.1 and I want to add a library to vendors. The library do not exists in packagist. I can't manage it with composer. When I install bundles or others vendors through composer, it manage autoload for me. But where to register autoload when the vendor is not managed with composer? You can add libraries to composer that are not in packagist. You must add them in the repositories array of your composer.json file. Here's how to load a github repository that has a composer.json file, even though it's not on packagist (for example a fork you would have done to fix a repository) :

Symfony 2 - How to delete a bundle?

ぃ、小莉子 提交于 2019-12-02 17:17:27
So my question is how to delete bundle I created? You create bundles with this console command: php app/console generate:bundle --namespace=Test/BlogBundle --format=yml And thats awsome but what if I need to delete this bundle? Is there a console command to delete a bundle I dont need any more? I know that when you create new bundle from console, you: 1. create /src/Test/BlogBundle directory 2. change /app/config/routing.yml file to include routes 3. include your new bundle in /app/Resources/App.Kernel.php 4. I think there is something changed in /app/cache/... Now what would be correct way of

Symfony get form data in controller

喜你入骨 提交于 2019-12-01 17:26:00
问题 I have this view: //login.html.twig <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>MY APP</title> </head> <body> <form action="{{ path('conection') }}" method="post" name="formulario_login"> <label for="username">User:</label> <input type="text" id="username" name="_username" value="{{ last_username|default('') }}" /> <br /> <label for="password">Password:</label> <input type="password" id="password" name="_password" /> <br /> <input