问题标签 [symfony3.x]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
5 回答
12450 浏览

php - 如何配置 PhpStorm 以使用 symfony/phpunit-bridge

在使用Symfony 3.3 时,我在配置 PhpStorm IDE 以使用http://symfony.com/doc/current/components/phpunit_bridge.html时遇到问题。

我决定只下载phpunit.pharbin使用它。

Symfony 3.4(和Symfony 4),甚至没有phpunit.xml.dist开箱即用,所以使用方便存在问题phpunit.phar

我已经使用 flex 安装了 PHPUnit:

这创建了 phpunit.xml.dist 并且我能够通过以下方式从命令行运行测试:

但是我又不能让 PhpStorm 使用它。

所以我下载phpunit.phar了它,它可以与提供的 phpunit.xml.dist 一起使用。

问题一: PhpStorm IDE 有没有办法使用 phpunit-bridge?

问题 2: Symfony 4(phpunit-bridge 或 vanilla phpunit.phar)的最佳实践是什么?

0 投票
1 回答
1074 浏览

symfony - 独白不记录上下文

在我的 Symfony 3.4 中。应用程序我已经配置了一个自定义记录器:

当我在我的代码中使用这个记录器时,我已经正确注入了通道“my_channel”。

在屏幕上,我得到正确显示的 $data 信息:

但不在我的日志中,上下文为空:

问题:如何将上下文也记录到我的日志文件中?

0 投票
1 回答
961 浏览

symfony - Symfony - composer update - Dependency Injection Configuration class not found

Our project is partly made of three bundles, two of them consist of a web backend application and an associated API consumed by our Customer's Frontend Single Page Application, the last one "CoreBundle" is where common resources live.

These bundles all have a DependencyInjection's (DI) bundle sub-directory but do not have Configuration class at all since none of them has any specific configuration. We use the DI component as suggested in the documentation, there is in theory no special case in this project that may influence the configuration loading mechanism.
This has been working well Until now (Symfony 3.3.2).

In an intent of updating symfony/symfony from 3.3.2 to 3.4, composer post-install script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache generates 2 exceptions:

In Consistency.php line 337: Class Bundle\CoreBundle\DependencyInjection\Configuration\Configuration not found
In Consistency.php line 285: Class Bundle\CoreBundle\DependencyInjection\Configuration\Configuration not found

Exception trace:

Adding a Configuration class, with its getConfigTreeBuilder() method returning a new ("empty") Treebuilder instance, makes the exception point out another bundle. I did so for our three bundles and the exception now points out one of Sensio's own bundles instead.

In Consistency.php line 337: Class Sensio\Bundle\DistributionBundle\DependencyInjection\Configuration\Configuration not found …</p>

Here are a few Composer warnings spawning before the exception gets thrown:

Executing rm -rf var/cache/* did not help.
Running only bin/console cache:clear throws this same exception.

Now that our bundles implementation seem to not have anything to do with this issue, I have even less idea of what may be the root of the problem. That said, the line "spl_autoload_call() at n/a:n/a" looks strange … May be some Symfony dependencies should be forced to some versions … ? (By the way changelog did not provide helpful hint of a potential cause)

Thank you for your help.

0 投票
1 回答
978 浏览

forms - Symfony3:多步形成并在前进后冲洗

我有一个表格可以在我的数据库中添加一个新的处方者。第一步包括告知开处方者的各种信息。

然后,我在添加之前检查是否有类似的处方者(第二步,第二个表格),如果有,我要求用户确认。

简而言之,我有一个 1-step 表格或 2-steps 表格,具体取决于重复项。

我尝试使用 CraueFormFlowBundle,但我不知道如何实现我的有条件的第二步。我的测试没有结果。所以我决定在我的控制器中使用 forward 方法,我喜欢它!

但是,我无法在第二步结束时(转发后)冲洗我的开药者,我有这个错误:Unable to guess how to get a Doctrine instance from the request information for parameter "prescriber".

addAction (= 步骤 1)

addConfirmAction (= 步骤 2)

我认为问题出在我有 2 个表单提交的事实......

0 投票
2 回答
245 浏览

php - dql选择返回空结果symfony 3

我正在尝试从包含关键字的数据库中获取所有视频,这是使用 Symfony 3 构建的 API REST。这是 URL 的示例

“prueba”是我要查找的关键字

这是功能..

结果应该是一个带有 4 个视频的 JSON .. 但我明白了

其中“data”是一个包含视频数据的数组

有人知道我想念什么吗?dql 咨询.. 正确吗?

有人可以告诉我是什么错误吗?我需要一个线索.. dql 咨询是否正确?

0 投票
2 回答
153 浏览

doctrine-orm - 扩展 UserManager 以按关系搜索用户(symfony3)

我安装了 FOSUserbundle 和 HWI Oauth 包。我的问题是:我想从存储在关系中的用户实体访问数据。我想访问 FOSUserProvider 中 UserInSocialNetworks 中的 social_network_slug 和 social_identifier 字段中的数据。这个想法是,一个用户可以拥有多个社交网络登录名。(1:n)- 当我使用我的 google/facebook 等登录名登录时,我想检查表 user_in_social_networks 是否已经存在社交网络的 ID。

实体类来存储所有用户的社交媒体登录:

扩展的 FOSUBUserProvider 类:

从现在开始我检查的内容:我无法访问 FOSUBUserProvider 类中的 entitymanager,也无法通过这种方式进行搜索:

因为这是一种关系。感谢您的任何想法!

0 投票
1 回答
1150 浏览

apache - 使用 Symfony 开发模式执行并发请求时 Apache 崩溃

我正在制作一个 symfony 3.4 应用程序作为 REST 服务(所以我安装了常用的 JMS Serializer、FoSRest 和 lexik/jwt-authentication-bundle)并在 XAMPP(Windows 10)上对其进行测试。
当我使用 app_dev.php 作为端点通过我的前端应用程序发出 XHR 请求时,它(非常)经常发生 Apache 在同时发出 2 个以上的请求时崩溃。
在这里和那里阅读看起来这个问题通常是由尝试写入会话文件引起的,因为 symfony 默认会话处理程序是session.handler.native_file.
所以我首先尝试放置null(根据文档,它使用本机 PHP 会话处理程序),这使得崩溃发生的频率降低但没有完全解决问题
然后我尝试使用Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler这使得崩溃发生的次数比以前更少,但仍然偶尔会发生崩溃

现在我正在使用数据库作为会话处理程序,尽管我注意到当我发出 XHR 请求时没有在数据库上写入会话(虽然如果我打开应用程序提供的普通网页则它会这样做),这应该'让我感到惊讶,因为我设置了我security.yml的 REST 路由必须是无状态的,但是玩弄handler_id配置会影响我的 apache 崩溃的频率

如果我打开由同一个应用程序提供的多个网页,则不会发生同样的事情,如果我使用生产端点(app.php)也不会发生同样的事情。

有没有办法彻底解决这个问题?

编辑:根据要求

你能添加apache错误日志和php错误日志吗?

每次重新启动时,它都会像这样重复。我注意到了这条线:AH00428: Parent: child process 29076 exited with status 3221226356 -- Restarting.这可能很有趣

当你说 apache crash 意味着你必须重新启动 apache,或者你只是得到一个错误?你得到哪个错误?

我只是得到通常的应用程序崩溃窗口说“Apache 已停止工作”,如果我单击“关闭应用程序”它会自行重新启动,导致崩溃的请求只是失败,没有状态代码或错误消息(这是预期的,因为与服务器的连接停止)。如您所见,除了该状态代码外,日志中没有特定错误

你是如何设置 apache 和 php mod_apache、php-fpm 的?你有哪些 apache 服务器限制,有多少 php 工作者?

我不确定如何回答这个问题,我使用的是 XAMPP 包中的股票 apache 和 php,没有对配置进行编辑。我可以告诉你 php 是作为 apache 处理程序加载的,所以没有 CGI 或 FastCGI。无论如何在简单页面上或在 Symfony 中使用生产模式它都可以正常工作

消息:

  1. 我发现,由于我正在执行 CORS 请求,它正在为每个请求创建一个会话文件,我修复了这个问题并稍微改善了我的问题,但它仍然存在

  2. 我曾尝试使用 redis 作为 PHP 的会话处理程序,但它实际上让事情变得更糟

  3. 我做了一个简单的测试,我在同一个页面(使用会话)中调用了 1000 次,只要我把它放在session_write_close();最后,它就可以正常工作,否则它会崩溃

0 投票
2 回答
340 浏览

symfony - FOSUserBundle :根据电子邮件密码和第三个字段对用户进行身份验证

如何覆盖FOSUserBundle以便我可以根据以下组合注册/验证用户:

Email ID + Password + GroupID而不仅仅是email + password

因此电子邮件将不再是唯一的,但组合email + groupid将使用户唯一(每个组)并且可以拥有独立的密码。

我将FOSUserBundle v2.0.2Symfony 3.4.x 一起使用

具有有效登录 ID 的 fos_user 表行示例:

0 投票
0 回答
1824 浏览

symfony - Symfony 3 - 尝试在两个包的两个实体之间建立关系时“在链配置的命名空间中找不到类”

使用 Symfony 3.4.2 ,我正在尝试在两个不同捆绑包的两个实体之间建立关系,这两个捆绑包使用位于不同服务器上的自己的数据库。

换句话说,我们有两个数据库,然后是两个实体管理器

  • 一个现有的 MariaDB 数据库 [person],它存储一个“person”表,供许多其他应用程序使用。
  • 一个专用于该应用程序的新 MariaDB 数据库 [应用程序]。

请注意,在这种情况下我无法更改任何内容(旧版应用程序必须仍在运行)。尽管计划“在未来”用 REST Api 替换 [person] 数据库

遵循 Symfony 文档(https://symfony.com/doc/3.4/doctrine/multiple_entity_managers.html),这给出了以下 app/config/config.yml 文件:

由于“person”表将被许多其他应用程序使用,我选择创建一个单独的包。

就实体而言,我有 3 个实体:

  1. Acme/AnotherBundle/实体/人
  2. AppBundle/实体/书
  3. AppBundle/实体/BookInterest

第一个实体的生成没有任何错误。

AppBundle/Entity/Book 和 AppBundle/Entity/BookInterest 实体是通过生成的,bin\console generate:doctrine:entity没有任何问题。

在更新数据库模式之前,我按照 Symfony 文档 ( http://symfony. com/doc/3.4/doctrine/associations.html)。

但是,当我尝试通过 更新架构时bin\console doctrine:schema:update --force --em=default,出现以下错误消息:

在 MappingException.php 第 37 行:在链配置的命名空间 AppBundle\Entity 中找不到类 'Acme\AnotherBundle\Entity\Person'

添加“使用 Acme\AnotherBundle\Entity\Person;” 在 \src\AppBundle\Entity\BookInterest.php 的顶部并通过清除缓存bin\console cache:clear不能解决问题。

我是否遗漏了app/config/config.yml配置文件或\src\AppBundle\Entity\BookInterest.php实体类文件中的某些内容?

Doctrine2 无法处理两个实体经理之间的一种关系?

我还发现了一篇关于类似问题的(相当旧的)帖子(使用与多个实体管理器的关系),这表明 Doctrine2 无法做到这一点(由于使用了两个实体管理器)。

如果情况仍然如此,处理这种情况的最佳方法是什么?

在 AppBundle/Entity/BookInterest 中使用一个没有关系的简单整数字段来存储 person_id 并在 BookInterestController 中创建手动验证检查(然后是手动查询)是一种好习惯吗?

非常感谢您提供解决该案例的任何提示(和良好的实践建议)!:-)

0 投票
1 回答
2288 浏览

php - Doctrine symfony 删除具有 OneToMany - ManyToOne 关系的实体

我有两个实体活动和 BulleManager。我使用 OneToMany - ManyToOne 来表示它们之间的关系。问题是当我删除 BulleManager 实体中的一行时,Activity 实体中的相关行也被删除,这不是我喜欢的行为。当拥有方(BulleManager)实体被删除时,我只想将“NULL”设置为反转方实体(活动)。

欢迎您的解决方案。