Tag: symfony

使用Symfony2获取Twig模板中的环境名称

有没有办法在Twig模板中获取当前环境的名称? 我想设置一些CSS样式值取决于它。

phpunit随机重新开始testing

我正在尝试使用PHPUnittesting我的symfony2应用程序。 我有一个项目,一切正常,但在另一个项目上,我有这样一个奇怪的行为,即PHPUnit在所有testing结束时随机停止执行testing套件,并在完成testing套件并编写代码后重新启动或重新启动testing覆盖。 其他时候它正常运行。 下面是一些输出来显示正在发生的事情(testing正在重新开始): PHPUnit 3.6.10 by Sebastian Bergmann. Configuration read from C:\workspace\cllctr\app\phpunit.xml ……………………………………………………….. 65 / 83 ( 78%) ………..PHPUnit 3.6.10 by Sebastian Bergmann. Configuration read from C:\workspace\cllctr\app\phpunit.xml ……………………………………………………….. 65 / 83 ( 78%) …PHPUnit 3.6.10 by Sebastian Bergmann. Configuration read from C:\workspace\cllctr\app\phpunit.xml ……………………………………………………….. 65 / 83 ( 78%) …………PHPUnit 3.6.10 by Sebastian Bergmann. Configuration […]

Angularjs在symfony2应用程序上

我正在使用前端使用大量JavaScript的SF2应用程序。 SF2为我提供了一个很好的方法来构build一个不错的REST应用程序,使用教义pipe理我的数据库,为模板使用树枝等等,但是我想使用Angularjs。 我知道angularjs SF2是2种不同的框架与不同的方法,但我想知道做什么最好的方法是这样的。 它甚至值得吗? 如果是的话,你认为什么是更清洁和最有效的解决scheme? 也许使用PHP而不是树枝模板使用angularjs大括号?

如何sortingfindAll Doctrine的方法

我一直在阅读Doctrine的文档,但是我一直没能findsortingfindAll()结果的方法。 我正在使用symfony2 +原则,这是我在我的控制器中使用的声明: $this->getDoctrine()->getRepository('MyBundle:MyTable')->findAll(); 但我希望结果按照用户名升序排列。 我一直在试图通过这样一个parameter passing数组: findAll( array('username' => 'ASC') ); 但它不起作用(它也不抱怨)。 有没有办法做到这一点,而不build立一个DQL查询?

Doctrine 2在manyToOne关系中不能使用nullable = false?

User有一个关联的Package 。 许多用户可以参考相同的包。 没有定义Package User不能存在。 User应该拥有这个关系。 关系是双向的,所以Package中有零个或更多的用户。 这些要求在Doctrine 2中导致了ManyToOne关系和Package OneToMany关系。但是user表(即外键)中的package_id允许null值。 我试过设置nullable=false但命令: php app/console doctrine:generate:entities DL –path="src" –no-backup 说关系ManyToOne没有nullable为nullable的属性。 我错过了什么? class User { /** * @ORM\Id * @ORM\Column(type="integer") * @ORM\GeneratedValue(strategy="AUTO") */ private $id; /** * @ORM\ManyToOne(targetEntity="Package", inversedBy="users") */ private $package; } class Package { /** * @ORM\Id * @ORM\Column(type="integer") * @ORM\GeneratedValue(strategy="AUTO") */ private $id; /** * […]

在Twigpath中添加多个参数

如何在Twigpath中添加多个参数? 假设你有这条路线: article_show: pattern: /article/{slug} defaults: { _controller: AcmeArticleBundle:Article:show } 你可以在你的树枝模板中做到这一点: {{ path('article_show', { 'slug': article.slug }) }} 但是如果你在你的路由文件中有这个: _files_manage: pattern: /files/management/project={idproject}&user={iduser} defaults: { _controller: AcmeTestBundle:File:manage } 看起来他们没有在他们的文件中包括这个。

在模板中访问已login的用户

我正在使用FOSuserbundle开始使用用户注册https://github.com/FriendsOfSymfony/FOSUserBundle 我已经注册/login和注销。 我现在要做的是抓取login的用户数据,并将其显示在我的网站的每个页面上。 像“Hi用户名”的标题types的东西。 这似乎是embedded一个控制器在我的应用程序/资源/ views / base.html.twig是最好的方式来做到这一点http://symfony.com/doc/current/book/templating.html#embedding-controllers 所以我写了我的控制器来访问用户configuration文件数据。 我想不出的是如何在我的embedded式控制器中访问FOS方法。 所以从我的Acme / UserBundle / Controller / UserController.php我想这样做: public function showAction() { $user = $this->container->get('security.context')->getToken()->getUser(); if (!is_object($user) || !$user instanceof UserInterface) { throw new AccessDeniedException( 'This user does not have access to this section.'); } return $this->container->get('templating') ->renderResponse('FOSUserBundle:Profile:show.html.'.$this->container ->getParameter('fos_user.template.engine'), array('user' => $user)); } 我从抢:vendor / bundles […]

Symfony 2中的“弱路线”是什么?

当使用PHPStorm的Symfony2插件时,我有时会看到一个弱路线警告: 这是什么意思?

Symfony 2 EntityManager注入服务

我创build了自己的服务,我需要注入EntityManager的教条,但是我没有看到__construct()在我的服务上被调用,并且注入不起作用。 这里是代码和configuration: <?php namespace Test\CommonBundle\Services; use Doctrine\ORM\EntityManager; class UserService { /** * * @var EntityManager */ protected $em; public function __constructor(EntityManager $entityManager) { var_dump($entityManager); exit(); // I've never saw it happen, looks like constructor never called $this->em = $entityManager; } public function getUser($userId){ var_dump($this->em ); // outputs null } } 这是我的包中的services.yml services: test.common.userservice: class: Test\CommonBundle\Services\UserService […]

如何修复“添加myBundle到asseticBundleconfiguration”symfony2exception?

当我尝试使用TWIG {% javascript %}标记链接到我的.js文件时,它返回了以下exception: An exception has been thrown during the compilation of a template ("You must add CompetitiongameBundle to the assetic.bundle config to use the {% javascripts %} tag in CompetitiongameBundle:game:index.html.twig.") in "CompetitiongameBundle:game:index.html.twig". 我的index.html.twig看起来像: {% javascripts 'CompetitiongameBundle/Resources/views/public/js/*'%} <script type="text/javascript" src="{{ asset_url }}" ></script> {% endjavascripts %} Hello {{ name }}! <a href='{{ nexturl }}' […]