symfony-2.1

Symfony2 get validation constraints on an entity

 ̄綄美尐妖づ 提交于 2019-11-29 12:05:29
问题 Im working on a method to get all validation constraints of an entity (what i am trying to achieve is to return this data in JSON and apply the same constraints on client side using JQuery Validation Plugin), however im having some trouble getting the constraints, Here is my current code: $metadata = new \Symfony\Component\Validator\Mapping\ClassMetadata("Namespace\JobBundle\Entity\Job"); $annotationloader = new AnnotationLoader(new AnnotationReader()); $annotationloader->loadClassMetadata(

Symfony2 validation doesn't work when Entity Relationships/Associations

偶尔善良 提交于 2019-11-29 10:30:30
controller public function indexAction(Request $request) { $user = $this->container->get('security.context')->getToken()->getUser(); $owner = $user->getId(); $first = new First(); $first->setOwner($owner); $second = new Second(); $second->setOwner($owner); $second->setFirst($first); $form = $this->createForm(new SecondType(), $second); if ($request->getMethod() == 'POST') { $form->bindRequest($request); if ($form->isValid()) { $em = $this->get('doctrine')->getEntityManager(); $em->persist($first); $em->persist($second); $em->flush(); } } return $this->render('MySampleBundle:Home:index.html

Customize form field rendering

喜夏-厌秋 提交于 2019-11-29 09:50:35
问题 I would like to customize the rendering of a form field in the edit page from sonata admin bundle to include an applet that uses the text content of a field. I know that I have to edit the configureFormFields function in the admin class, but I need to know 3 things: What is the syntax to provide a field form template Where to put the template file ( which directory ) What the template have to looks like. 回答1: Found a solution What i have done is: Created a field type, lets call it myfieldType

How do I add an unbound field to a form in Symfony which is otherwise bound to an entity?

ε祈祈猫儿з 提交于 2019-11-29 06:38:20
问题 Maybe I'm missing the obvious but how do I (or can I) add an extra "unbound" field to a Symfony form that is otherwise bound to an entity? Let's say I have an entity with fields first_name and last_name . I do the typical thing in my form class buildForm method. $builder ->add('first_name') ->add('last_name') ; and this in my controller: $editForm = $this->createForm(new MyType(), $entity); That works nicely but I'd like to add another text box, let's call it "extra", and receive the value in

Symfony2 is_granted('IS_AUTHENTICATED_FULLY') during 404 error page display, causing ResourceNotFoundException

亡梦爱人 提交于 2019-11-29 02:48:50
问题 I have setup custom error pages to display for certain HTTP errors in the folder: app/Resources/TwigBundle/views/Exception/ The 403 page ( error403.html.twig ) works and displays as expected. The 500 page ( error500.html.twig ) works and displays as expected. The 404 page ( error404.html.twig ) throws a 500 server error: PHP Fatal error: Uncaught exception 'Symfony\Component\Routing\Exception\ResourceNotFoundException' The error is being thrown by doing an auth check to display certain menu

Troubleshooting “require_once(../bootstrap.php.cache): failed to open stream: No such file or directory”

≡放荡痞女 提交于 2019-11-29 02:06:52
问题 I am trying to redeploy a Symfony 2.1x project I have been working on and app_dev.php is failing because it can't find app/bootstrap.php.cache . This file is omitted from the project's git repository because I used Symfony2's recommend .gitignore file: # .gitignore /app/bootstrap* Am I correct in thinking that app/bootstrap.php.cache is generated during the $ php composer.phar install process? If this is the case then I will include for you my composer.json : // composer.json { "name":

How to avoid composer discard changes message

我与影子孤独终老i 提交于 2019-11-29 01:45:47
问题 I'm updating symfony verdors via composer. I always do it using: php composer.phar update But recent version of composer, before update each package show a message like this: - Updating doctrine/data-fixtures dev-master (a95d783 => a28b6bd) The package has modified files: M .gitignore M .gitmodules M LICENSE M README.md M UPGRADE M composer.json M lib/Doctrine/Common/DataFixtures/AbstractFixture.php M lib/Doctrine/Common/DataFixtures/DependentFixtureInterface.php M lib/Doctrine/Common

Symfony2.1: Unable to find the controller for path “/login_check”

ε祈祈猫儿з 提交于 2019-11-28 21:30:42
I used the "Using a traditional login form" tutorial from symfony.com to authentificate my users. With a simple http auth it works great. After the login was submitted I get this Exception: Unable to find the controller for path "/login_check". Maybe you forgot to add the matching route in your routing configuration? Well, in the tutorial I read: You will not need to implement a controller for the /login_check URL as the firewall will automatically catch and process any form submitted to this URL. I defined the routes and set the firewall settings: security.yml firewalls: dev: pattern: ^/(_

When are user roles refreshed and how to force it?

ⅰ亾dé卋堺 提交于 2019-11-28 19:22:40
First off, I'm not using FOSUserBundle and I can't because I'm porting a legacy system which has its own Model layer (no Doctrine/Mongo/whatsoever here) and other very custom behavior. I'm trying to connect my legacy role system with Symfony's so I can use native symfony security in controllers and views. My first attempt was to load and return all of the user's roles in the getRoles() method from the Symfony\Component\Security\Core\User\UserInterface . At first, it looked like that worked. But after taking a deeper look, I noticed that these roles are only refreshed when the user logs in.

Testing Controllers in Symfony2 with Doctrine

孤者浪人 提交于 2019-11-28 18:59:23
I have created a very simple REST controller in Symony2 with Database insert/updates/deletes in the controller actions. Is there a nice way to write unit/integration tests for these controller actions without polluting the production database? Do I have to work with different environments - or is there a proposed way from the framework vendor for this? Current Controller Example: public function postAction() { $json = $this->getRequest()->getContent(); $params = json_decode($json); $name = $params->name; $description = $params->description; $sandbox = new Sandbox(); $sandbox->setName($name);