Symfony2

Symfony2 Doctrine Custom Repository Class [Semantical Error] line 0, col 14 near 'Project p': Error: Class 'Project' is not defined

匿名 (未验证) 提交于 2019-12-03 02:35:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm really new in Symfony 2 and Doctrine, and have a simple problem: There is a pretty simple code in my repository: <?php namespace BakeryIT\BakeryBundle\Entity; use Doctrine\ORM\EntityRepository; class ProjectRepository extends EntityRepository { public function findHistory(){ return $this->getEntityManager() ->createQueryBuilder() ->select('p') ->from('Project','p') ->getQuery() ->getResult(); } } And two simple functions in my controller: <?php namespace BakeryIT\BakeryBundle\Controller; /* ... */ class ProjectController extends

Symfony2 “class not found in the chain” in two bundle relationship

匿名 (未验证) 提交于 2019-12-03 02:31:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: In an attempt to define a one-to-many relationship across bundles the following occurs: The class 'Mana\ClientBundle\Entity\Member' was not found in the chain configured namespaces Mana\SplitBundle\Entity Update 3: I've now seen conflicting answers that the relationship can and cannot be accomplished. On the assumption that it can (because others here at stackoverflow seem to have done it), what configuration is required other than registering the bundles in AppKernel.php and entering the annotations in the entities? The resolve_target

Symfony2, Dynamic DB Connection/Early override of Doctrine Service

匿名 (未验证) 提交于 2019-12-03 02:29:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a Core config Database, each row is an 'App' with some basic config etc. Once you have chosen your app, I want to connect to a database using a property of that row (ID), and the host may also change based on the row. What I want is to register a service that sets up the Doctrine service using these details if you are in a place on the site that it's required (which I know based on URI). I am using the Entity manager, and various Doctrine Listeners/Event subs I've played around with the ConnectionFactory, but this appears to cause

Symfony2: The CSRF token is invalid. Please try to resubmit the form

匿名 (未验证) 提交于 2019-12-03 02:16:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a form wher I have to fill in some information in a field. Even if I put something inside, I am getting the error: The CSRF token is invalid. Please try to resubmit the form Related to this question: symfony2 CSRF invalid I am using correctly the $form->bindRequest() if ($this->getRequest()->getMethod() == 'POST') { $form->bindRequest($this->getRequest()); if ($form->isValid()) { ... } Here is my template (twig) code: <div class="item item-last"> <h1>Create Affiliation</h1> {% if valid == false %} <div class="error"> {{ form_errors

how to update symfony2/doctrine entity from a @Groups inclusion policy JMSSerializer deserialized entity

匿名 (未验证) 提交于 2019-12-03 02:14:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm trying to update symfony2/doctrine entities using JMSSerializer with an @ExclusionPolicy:None @Groups Inclusion Policy. * @Serializer\ExclusionPolicy("none") */ class Foo { /** * @Serializer\Groups({"flag","edit"}) */ protected $id; /** * @Serializer\Groups({"edit"}) */ protected $name; /** * @Serializer\Groups({"flag"}) */ protected $flag; /** * @Serializer\Exclude() */ protected $createdBy; } reference: http://jmsyst.com/libs/serializer/master/reference/annotations the result for the following record: Foo (id:1, name:'bar', flagged

Symfony2 - checking if file exists

匿名 (未验证) 提交于 2019-12-03 02:14:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a loop in Twig template, which returns multiple values. Most important - an ID of my entry. When I didn't use any framework nor template engine, I used simply file_exists() within the loop. Now, I can't seem to find a way to do it in Twig. When I display user's avatar in header, I use file_exists() in controller, but I do it because I don't have a loop. I tried defined in Twig, but it doesn't help me. Any ideas? 回答1: If you want want to check the existence of a file which is not a twig template (so defined can't work), create a

Symfony2 Use PHP Class Constant in YAML Config?

匿名 (未验证) 提交于 2019-12-03 01:59:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I know this is probably not possible, but is there a clean way to use a PHP class constant within a YAML config/services/etc. file for Symfony2? For example, if I have this: namespace My\Bundle\DependencyInjection; class MyClass { const MY_CONST = 'cookies'; } Is something like this possible (in a .yml file): services: my_service: class: Some\Class arguments: - %My\Bundle\DependencyInjection\MyClass::MY_CONST% That'd go a long way in helping maintain consistency between the two. 回答1: In versions before Symfony 3.2, injecting PHP-constants

Translate select options in Symfony2 class forms

匿名 (未验证) 提交于 2019-12-03 01:55:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm using a class form in Symfony2 Beta3 as follows: namespace Partners\FrontendBundle\Form; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilder; class ConfigForm extends AbstractType { public function buildForm(FormBuilder $builder, array $options) { $builder->add('no_containers', 'choice', array('choices' => array(1 => 'yes', 0 => 'no'))); ... I want to translate the 'yes' and 'no' options, but I don't know how to use the translator here. 回答1: You can use the translation resources as usual. This worked for me:

Symfony2 Error: No mapping file found named

匿名 (未验证) 提交于 2019-12-03 01:46:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I am using Symfony2 and when i try to generate the schema ($ php app/console doctrine:generate:schema) i got an error.. [ Doctrine \ORM\Mapping\MappingException ] No mapping file found named 'xxx.UserBundle.Entity.User.php' for class 'xxx\UserBundle\Entity\User' . I only have 2 Bundles in the proyect: UserBundle FileBundle I connect the FileBundle with the UserBundle with this code: /** * @ORM\ManyToOne(targetEntity="xxx\UserBundle\Entity\User") **/ protected $user ; The headers of the files are something like this: namespace xx

Symfony2 - Doctrine - From SQL to DQL

匿名 (未验证) 提交于 2019-12-03 01:45:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm working on PHP project based on Symfony2 and I want this below to works on Symfony2 by Doctrine but actually I get this error by using the "...FROM xx JOIN (SELECT...." : [Semantical Error] line 0, col 176 near '( SELECT': Error: Class '(' is not defined. The final DQL statement that I want to make work is : return $this->getEntityManager() ->createQuery( "SELECT u.username, m1.id, n.id as notification, n.vue, u.lastActivity, LEFT(m1.message,60) as Message, m1.lu, m1.dateEnvoi, i.image FROM MCoreBundle:Messages m1 JOIN ( SELECT m.from,