问题标签 [symfony-2.6]

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 回答
1728 浏览

php - 属性不存在时 JMS 序列化程序错误

我正在创建一个 symfony2 项目并使用 JMS 序列化程序包来序列化我的对象以进行数据库存储(我知道这不是最好的方法)。

但是现在我的问题是,当我更改对象的属性并反序列化 Json 字符串时,JMS 序列化程序会忽略不存在的属性而不是抛出错误,这实际上很棒。然而,我想记录这样的事件。

下面是一个例子来说明我的问题

我的数据库中的 Json 字符串:

测试类:

反序列化方法:

这导致:

但是当我更改我的 Testclass 并将标题重命名(或删除)时,比如说“title2”,反序列化器会忽略 Json 字符串中的“title”属性。结果是:

那么那里没有问题。数据库中的数据是错误的。但我想记录这个问题。我该怎么做?如果可能的话,我不想弄乱 JMS 序列化程序的代码(因为我不能再更新它了)。在我的 TestClass 中寻找空属性也不是最好的方法,因为它们可以为空。

0 投票
2 回答
5410 浏览

php - Symfony2 - Twig updates are not rendering

I am a beginner in Symfony2. I have created my first template and I can access to it through the URL http://localhost/mylibrary-web/web/app_dev.php/hello/Test.

Here the content of my src/MyLibrary/LibraryBundle/Resources/views/Default/index.html.twig file :

I do not have the toolbar (because I do not have the </body> element, but if I update the index.html.twig file with :

nothing changes. These modifications are not considered. The old content is still display when I call the URL http://localhost/mylibrary-web/web/app_dev.php/hello/Test.

I tried to clear the cache with the command line php app\console cache:clear. I also tried to hard delete the cache by deleting the app\cache directory. Finally, I tried to add the following line to the config_dev.yml file :

Unfortunately, nothing changes, I still have the old content displayed.

Am I missing something to update the twig file ?

Thank you in advance for your help !

Edit :

Here the code of the src/MyLibrary\LibraryBundle\Controller\DefaultController.php file :

and the result of the command line php app\console route:debug :

Edit 2 :

Here the definition of the my_library_library_homepage route :

and here the result when I grep Hello {{ name }}! :

  • C:\wamp\www\mylibrary-web\vendor\sensio\distribution-bundle\Sensio\Bundle\DistributionBundle\Resources\skeleton\acme-demo-bundle\Acme\DemoBundle\Resources\views\Demo\hello.html.twig
  • C:\wamp\www\mylibrary-web\vendor\sensio\distribution-bundle\Sensio\Bundle\DistributionBundle\Resources\skeleton\acme-demo-bundle\Acme\DemoBundle\Resources\views\Secured\hello.html.twig
  • C:\wamp\www\mylibrary-web\vendor\sensio\generator-bundle\Sensio\Bundle\GeneratorBundle\Tests\Generator\BundleGeneratorTest.php
  • C:\wamp\www\mylibrary-web\vendor\twig\extensions\doc\i18n.rst
  • C:\wamp\www\mylibrary-web\vendor\twig\twig\doc\api.rst
  • C:\wamp\www\mylibrary-web\vendor\twig\twig\doc\intro.rst
0 投票
2 回答
268 浏览

symfony - 通过多个提供商的用户名查找用户 [symfony2]

我需要根据用户名或电子邮件地址在 symfony2 中找到一个用户对象。这不是用于登录,而是用于用户的其他操作。

我可以简单地请求(Doctrine2)存储库并从我的存储库类上的 UserProviderInterface 调用 loadByUsername 方法。

但是需要这样做的代码将在多个项目中使用,我需要它更通用一点。用户类/表可能不同,或者用户可能来自完全不同类型的提供者。

有没有办法像 Symfony2 本身在登录时使用的那样通过用户名查找用户?这样,无论用户提供者如何在 security.yml 中配置,它都可以工作。

Symfony2 中是否有一些我可以使用的服务?是否有“用户提供者服务”,我可以在其中调用类似“loadUserByUsername”之类的方法来尝试每个配置的提供者?

0 投票
2 回答
1478 浏览

twitter-bootstrap - Symfony2 - Use Bootstrap (glyphicon) and jQuery

I am a beginner with Symfony and I am trying to integrate a specific Bootstrap theme and jQuery.

Because of the css files, the js files and the fonts are shared by all the bundles, I put the resources into the app\Resources\public directory.

In this directory, I have the following architecture :

  • css
    • bootstrap.min.css
    • jquery-ui.min.css
    • my-css.min.css
  • fonts
    • glyphicons-halflings-regular.eot
    • glyphicons-halflings-regular.svg
    • glyphicons-halflings-regular.ttf
    • glyphicons-halflings-regular.woff
  • js
    • bootstrap.min.js
    • jquery-1.9.1.min.js

I also have a layout.html.twig file in the app\Resources\views directory which is my main layout. In this layout, I load the css and the js files with the following twig blocks :

The CSS files are correctly loaded in my pages, but I have an error when I use glyphicon. The icons, on a button for example, are not loaded and in the console of Firefox, I have an error 403 :

I try to modify the security.yml file without success :

How can I authorize the access to the fonts directory ? Thx for your help !

0 投票
2 回答
333 浏览

symfony - is it possible to call an entity from view ( php template ) in symfony2

I got a dynamic content in layout which is takes vales from database. What is the best way to achieve this rather than passing values from controller.

Is it possible to call an entity from view? I am using php template.

0 投票
1 回答
1674 浏览

php - security.yml 中的 Symfony2 错误

我需要帮助来解决这个错误,我正在使用 symfony 2.6

ServiceNotFoundException:服务“fos_user.security.login_manager”依赖于不存在的服务“security.context”。

0 投票
1 回答
268 浏览

php - ServiceNotFoundException:HWIOAuthBundle + Salesforce 资源所有者

我正在尝试安装和配置HWIOAuthBundle捆绑包,但我遇到了一些问题。这就是我所做的:

1) 在以下位置启用捆绑包AppKernel.php

2)将此行添加到config.yml

3)在文件中写入以下内容hwi.yml

4) 在开头添加路线routing.yml

当我在浏览器中调用时:http://applocal.dev/app_dev.php我收到此错误:

CheckExceptionOnInvalidReferenceBehaviorPass.php 第 58 行中的 ServiceNotFoundException:服务“hwi_oauth.security.oauth_utils”依赖于不存在的服务“hwi_oauth.resource_ownermap.admin_area”。

我在这里缺少什么?为什么会出现这个错误?

0 投票
1 回答
304 浏览

php - More than one firewall at Symfony2 project security.yml, how to deal with pattern?

I am working in a project where I will need two firewalls or secured areas. The first firewall/secured area will allow login/logout using HWIOAuthBundle using Salesforce as provider, the second firewall/secured area will allow login/logout through FOSUserBundle since this is for internal sysadmin and so on. I have a doubt trying to get security.yml file well setup since I don't know how to deal with pattern parameter. I have read Security reference but have not idea in how to do this. This is what I have at the moment:

How should I configure pattern in that case?

Update: firewalls not working

This is how the firewalls section looks after users answer:

But if I try http://appdev.local/app_dev.php/admin/ I got this error:

InvalidConfigurationException in BaseNode.php line 313: Invalid configuration for path "security.firewalls.admin_area": The check_path "/login_check" for login method "form_login" is not matched by the firewall pattern "^/admin".

Why?

Edit 2: what about if have FOSUserBundle && HWIOAuth work together?

As additional info and I forgot to tell this from the very beginning, I have and need FOSUserBundle && HWIOAuth installed and I am trying to get both working as should be. In that case this is how my routing.yml looks like:

How I should deal with prefix between FOSUserBundle && HWIOAuth?

0 投票
1 回答
392 浏览

php - FOSUserBundle + HWIOAuth 安全配置失败

我试图让 FOSUserBundle 和 HWIOAuth 一起工作以处理两种类型的用户的身份验证:代表和实习生。代表将开始使用 HWIOAuth,并将使用 Salesforce 和内部 FOSUserBundle。

我正在尝试设置所有内容,但我遇到了问题,因为当我尝试访问/login-salesforceor/admin路由时 Symfony 会抛出此错误。

BaseNode.php 第 313 行中的 InvalidConfigurationException:路径“security.firewalls.admin_area”的配置无效:登录方法“form_login”的 check_path“/login_check”与防火墙模式“^/admin”不匹配。

这是security.yml文件的内容:

我认为从HWIOAuth侧面我得到了所有设置(如果有人需要,可以分享)。这是routing.yml文件的内容:

我还缺少什么?这里有没有人让这两个人一起工作并可以分享他们的工作来完成它?

0 投票
0 回答
65 浏览

php - Symfony @Template(engine="php") 在 v2.6 上不起作用

我有一个使用 Symfony 2.1.x 构建的站点,现在我迁移到了 Symfony 2.6,但它总是试图找到树枝模板,这并不重要:

在每一个动作中。

我能做到的唯一方法是添加:

在动作结束时。

模板注释在 2.6 中不再起作用了吗?我还有什么需要做的吗?

在 config.yml 我有: