问题标签 [symfony-2.4]

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 投票
1 回答
2894 浏览

web-services - Symfony2 获取服务或获取容器服务

我刚刚在 Symfony2 中实现了我的第一个服务。

我注意到,在控制器方法中,我是否如此调用服务

或者

没有区别。

我得到同样的服务

差异在哪里?

0 投票
1 回答
758 浏览

symfony - Symfony2:Doctrine 不会在 OneToMany 关系上从 DB 返回 Collection

我的系统中有一个关系有问题。我很确定我这样做是正确的,并且我看不到代码中的错误。

我在下面粘贴了我的课程。基本上,当我执行 fighter.getFighterAttributes() 时,我得到一个空数组。类中的其他关系不会发生这种情况。此外,当我查看日志时,我看到正在调用其他关系,但没有调用 FighterAttributes()。

该表具有已使用实体插入的条目。

它必须是我的代码中的一个错误,但不确定:(

下面的类和日志。

日志如下:

请注意,没有 FighterAttribute 条目。

下面的类 FighterAttribute:

更新

此代码打印“null”

此代码打印 fighterAttributes:

输出:

这段代码:

输出:

谢谢您的帮助!!

0 投票
1 回答
883 浏览

web-services - Symfony2 - 从服务调用静态属性

我在 Simfony2 的控制器方法中调用服务。

完全没有问题,它工作正常。

当我尝试$b::$filter_accepted['brand']从先前实例化的服务中调用静态属性时,问题就来了。相反,我对其他方法没有问题$b->getParam()

有一种方法可以从服务中调用静态属性/方法吗?

0 投票
1 回答
1083 浏览

symfony - 关联原因实体的定义变得无效

我正在做一个项目,但我一直看到这个映射问题:

关联 PL\OrderBundle\Entity\Order#company 指的是未定义为关联的反向字段 PL\CompanyBundle\Entity\Company#id。

关联 PL\OrderBundle\Entity\Order#company 指的是不存在的反边字段 PL\CompanyBundle\Entity\Company#id。

关联 PL\OrderBundle\Entity\Order#medias 指的是不存在的拥有方字段 Application\Sonata\MediaBundle\Entity\Media#orders。

除了我阅读和阅读 Doctrine Docs 之外,我不知道如何解决它们,有什么问题?有什么帮助吗?以下是相关实体:

PL\OrderBundle\Entity\Order.php

\PL\CompanyBundle\Entity\Company.php

\Application\Sonata\MediaBundle\Entity\Media.php

0 投票
3 回答
8332 浏览

php - Symfony 2.4 你请求了一个不存在的服务“payment.encryption_service”

我正在将 symfony 项目从 2.0 迁移到 2.4 版本。我已经正确配置了所有的参数和服务。

但是 JMS 供应商出现了问题,这是显示的错误:

致命错误:未捕获的异常 'Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException' 带有消息“您已请求不存在的服务“payment.encryption_service”。' 在 C:\wamp\www\symfony\app\bootstrap.php.cache 第 2027 行

这条消息阻止了我,你有什么问题,有什么想法吗?

0 投票
1 回答
52 浏览

service - symfony2 在我自己的服务中使用全局验证器服务

我是 symfony 的新手,我在文档中看到,我可以在控制器中获取和使用验证器服务,例如:

在我编写的我自己的服务类中获取验证器服务的正确\简单方法是什么

谢谢你

0 投票
7 回答
9924 浏览

symfony - Symfony2 FOSElasticaBundle 更新与更新实体相关的所有实体的索引

我在我的项目中使用 FOSElasticaBundle 和 Doctrine,我的代码适用于使用 Doctrine 生命周期事件的选择性索引更新。我遇到的问题是我是否单独更新相关实体。

例如,一个人可能通过多对多关系与一家公司相关联。如果我直接通过公司实体更新公司名称,那么与公司相关的人员的索引将过期,仍然与公司的旧名称相关。

我对如何处理这个问题有点迷茫,有人有什么建议吗?我是否必须依赖计划的索引更新并同时处理不准确的索引数据,或者有没有一种方法可以调用与已更新实体相关的实体的更新。

我依靠 JMSSerializer 组来建立映射。我很欣赏这可能不是长期做事的最佳方式。

0 投票
1 回答
613 浏览

symfony - Symfony2 功能测试后执行

我对 Symfony2 进行了功能测试。它创建一些测试实体,进行测试并在测试完成后立即删除临时实体。

问题是当断言失败时,临时实体不会被删除。

请看下面的代码(我注释了未执行的行):

首先,是否有这样一种“总是”在测试后运行的方法,比如postExecutesymfony1 中的一个(可能是一个关闭方法)?

由于我的每个测试都以删除临时实体结束,所以我想在类上实现一种机制来删除这些实体。

我试图用 try/catch 块包装断言检查,但它没有意义。

0 投票
1 回答
71 浏览

symfony - Symfony 2.4 对丢弃会话的自定义响应

我正在我的应用程序中开发一个 RESTful 接口(使用 FOSRestBundle),我希望它始终返回一些有意义的 JSON 响应,即使非交互式身份验证失败(例如,用户在登录会话期间被锁定)。现在它只是重定向到登录页面。

我虽然可以使用某种核心异常监听器来实现它,但我不知道要监听哪些异常,甚至不知道它是否可能。

一些提示将不胜感激。

0 投票
2 回答
748 浏览

entitymanager - Symfony 2.4.2 - Pass the entity manager between controllers in different bundles

I'm having a problem with passing the entity manager between two layers of controllers.

The system I'm building has the following structure:

2 Bundles:

Core Bundle (let's call it Backend Controller)

This is the bundle that contains all the Models (entities) and business rules/logic.

API Bundle (call it Frontend controller)

Is responsible for checking the permissions of passed in api keys and communicating with the Core bundle to get the info.

Here's an example with the User controllers and entities:

UserController.php in APIBundle:

UserController.php in CoreBundle:

Please, tell me if I'm doing this right. It seems strange to pass the entity manager between the controllers every time.

Maybe there's a better way of doing that?

Does the idea between the separation of the bundles make sense?

Thank you, every idea is greatly appreciated.