symfony-2.1

Create 2 different entities with same form in Symfony 2

邮差的信 提交于 2019-12-03 17:12:39
Is it possible to create 2 related entities with the same form and action? If yes, how? I want to create a new User and its related Questionnaire in a 1step registration. Thanks, Luca You can create a form type for related entity (Questionnaire) and use it as a field type in User form type. It's called form nesting. // src/Acme/DemoBundle/Form/Type/QuestionnaireType.php namespace Acme\DemoBundle\Form\Type; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; class QuestionnaireType extends AbstractType { public function buildForm(FormBuilderInterface

Doctrine doesn't map fields from FOSUserBundle User class

独自空忆成欢 提交于 2019-12-03 16:52:27
I am using Symfony 2.1 RC1 and the FOSUserbundle on a Windows server running PHP 5.3.13. I have followed the instructions here but Doctrine doesn't create fields in the database for the properties inherited from the base FOS User class (only the fields from my class). Trying to login using the FOS login form produces the error: Unrecognized field: usernameCanonical I have the following Doctrine configuration: # Doctrine Configuration doctrine: dbal: driver: %database_driver% host: %database_host% port: %database_port% dbname: %database_name% user: %database_user% password: %database_password%

How to use ChoiceList in Symfony 2.1?

ぃ、小莉子 提交于 2019-12-03 16:36:31
I have a file containing a list of the US states. Alabama Alaska etc .. In symfony 2.0 I used ChoiceListInterface.php to use it in my form. I simply wrote this : <?php namespace MyBundle\Form; use Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface; class StateChoiceList implements ChoiceListInterface { public function getChoices() { $lines = file('listes/us_states.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); // fill the array $arr = array(); foreach ($lines as $line) { $arr[$line] = $line; } return $arr; } } But now there is 7 other functions to implement in

Symfony 2 - Best practice to upload an image on Amazon S3

人盡茶涼 提交于 2019-12-03 16:30:26
I have a form in which I have a file field to upload an image. I need to upload this image on Amazon S3. Building this step by step I started to upload the image on the local disk and it's now working. The upload is occurring inside my entity Page as it's recommended to test the success of the upload before to save the entity. I ended up with this chunk of code /** * @ORM\Column(name="objectThumbnail", type="string", length=255, nullable=true) */ protected $objectThumbnail; /** * This is not a column in the database but it's mapping a field from the form * * @Assert\File(maxSize="600000000") *

Form: Avoid setting null to non submitted field

牧云@^-^@ 提交于 2019-12-03 16:06:05
I've got a simple model (simplified of source): class Collection { public $page; public $limit; } And a form type: class CollectionType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add('page', 'integer'); $builder->add('limit', 'integer'); } public function setDefaultOptions(OptionsResolverInterface $resolver) { $resolver->setDefaults(array( 'data_class' => 'FSC\Common\Rest\Form\Model\Collection', )); } } My controller: public function getUsersAction(Request $request) { $collection = new Collection(); $collection->page = 1;

RegistrationFormType::buildForm() not compatible

笑着哭i 提交于 2019-12-03 14:32:16
I just upgrade my Symfony 2.0.12 project to 2.1. I also installed FosUserBundle, but when I run command php composer.phar update then composer output an error: Loading composer repositories with package information Updating dependencies Writing lock file Generating autoload files PHP Fatal error: Declaration of User\UserBundle\Form\Type\RegistrationFormType::buildForm() must be compatible with that of Symfony\Component\Form\FormTypeInterface::buildForm() in /home/mark/dev/proj/src/User/UserBundle/Form/Type/RegistrationFormType.php on line 38 Fatal error: Declaration of User\UserBundle\Form

Mixing route and query parameters using FOSRestBundle with Symfony

丶灬走出姿态 提交于 2019-12-03 13:54:31
问题 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

Symfony2: How to properly include assets in conjunction with Twig template inheritance?

余生长醉 提交于 2019-12-03 13:47:17
I'm currently developing a web application using Symfony 2.1.0. I've read through the Templating chapter of the book and I'm trying to include assets (right now, it's just a single stylesheet) in my web pages. I'm using the Three-level inheritance system that is mentioned in the book, and my application structure currently looks like this: app/Resources/views/ base.html.twig: base template, containing title , stylesheets and body blocks. src/My/PageBundle/Resources/views layout.html.twig: layout template (extending the base template), appending the main stylesheet to the stylesheet block, and

Force reauthentication after user permissions have been changed

不羁岁月 提交于 2019-12-03 12:42:57
In my application I can change user permissions and roles in backend. When a user is logged in and I remove a role of the user, the user can still access content which he actually is not permitted to access anymore, because he is missing the role. The changes take effect only when the user reauthenticates himself with logout/login. So my question is, can I access the session of a logged in user (not me)? I know I can access my own session and destroy it which forces me to login again. But I want to get the session of any user who is logged in. Is this possible? I could not find any resources

Testing database insert using Symfony

不羁的心 提交于 2019-12-03 09:13:08
Good day everyone, I have been looking into Test Driven Development a lot in the past few days and decided that I need to learn it as well. Although I can not figure out how to do it precisely. My project depends on the Symfony2.1.6 framework and Doctrine so I have some Database-tables that needs filling. Book (1,n) - (0,n) Genre Now if I want to insert a Genre-record I first need to write a test to ensure everything is being inserted as it should (or am I wrong?) The problem now is that I dont know how to access my Database as it is managed by the framework. The only thing I could find was