首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Symfony - FOSUserBundle配置文件视图在更新到Symfony 2.8后不起作用

Symfony - FOSUserBundle配置文件视图在更新到Symfony 2.8后不起作用
EN

Stack Overflow用户
提问于 2018-02-17 10:40:24
回答 1查看 262关注 0票数 0

我已经将Symfony项目从2.6版本升级到2.8版本,在此之后,当我请求纵断面图时,我收到错误500。错误是:

代码语言:javascript
复制
Error: Call to a member function has() on null

Stack Trace in vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php at line 350   -
 */
public function getUser()
{
    if (!$this->container->has('security.token_storage')) {
        throw new \LogicException('The SecurityBundle is not registered in your application.');
    }

当我运行composer show -i时,我看到下面的列表:

代码语言:javascript
复制
You are using the deprecated option "installed". Only installed packages are shown by default now. The --all option can be used to show all packages.
doctrine/annotations                 v1.4.0             Docblock Annotations Parser
doctrine/cache                       v1.6.2             Caching library offering a...
doctrine/collections                 v1.4.0             Collections Abstraction li...
doctrine/common                      v2.7.3             Common Library for Doctrin...
doctrine/dbal                        v2.5.13            Database Abstraction Layer
doctrine/doctrine-bundle             1.8.1              Symfony DoctrineBundle
doctrine/doctrine-cache-bundle       1.3.2              Symfony Bundle for Doctrin...
doctrine/inflector                   v1.1.0             Common String Manipulation...
doctrine/instantiator                1.0.5              A small, lightweight utili...
doctrine/lexer                       v1.0.1             Base library for a lexer t...
doctrine/orm                         v2.5.14            Object-Relational-Mapper f...
friendsofsymfony/jsrouting-bundle    1.5.3              A pretty nice way to expos...
friendsofsymfony/oauth-server-bundle 1.5.0              Symfony2 OAuth Server Bundle
friendsofsymfony/oauth2-php          1.2.2              OAuth2 library
friendsofsymfony/user-bundle         dev-master 9b3be01 Symfony FOSUserBundle
incenteev/composer-parameter-handler v2.1.2             Composer script handling y...
ircmaxell/password-compat            v1.0.4             A compatibility library fo...
jdorn/sql-formatter                  v1.2.17            a PHP SQL highlighting lib...
jms/aop-bundle                       1.3.0              Adds AOP capabilities to S...
jms/cg                               1.2.0              Toolset for generating PHP...
jms/di-extra-bundle                  1.9.1              Allows to configure depend...
jms/metadata                         1.6.0              Class/method/property meta...
jms/parser-lib                       1.0.0              A library for easily creat...
jms/security-extra-bundle            dev-master c4a5dda Enhances the Symfony2 Secu...
knplabs/knp-snappy                   v1.0.4             PHP5 library allowing thum...
knplabs/knp-snappy-bundle            v1.5               Easily create PDF and imag...
kriswallsmith/assetic                v1.4.0             Asset Management for PHP
liuggio/ExcelBundle                  v2.1.0             This is a Symfony2 Bundle ...
monolog/monolog                      1.23.0             Sends your logs to files, ...
paragonie/random_compat              v2.0.11            PHP 5.x polyfill for rando...
phpoffice/phpexcel                   1.8.1              PHPExcel - OpenXML - Read,...
phpoption/phpoption                  1.5.0              Option Type for PHP
phpunit/php-code-coverage            1.2.18             Library that provides coll...
phpunit/php-file-iterator            1.4.5              FilterIterator implementat...
phpunit/php-text-template            1.2.1              Simple template engine.
phpunit/php-timer                    1.0.9              Utility class for timing
phpunit/php-token-stream             1.2.2              Wrapper around PHP's token...
phpunit/phpunit                      3.7.38             The PHP Unit Testing frame...
phpunit/phpunit-mock-objects         1.2.3              Mock Object library for PH...
psr/log                              1.0.2              Common interface for loggi...
sensio/distribution-bundle           v2.3.22            The base bundle for the Sy...
sensio/framework-extra-bundle        v3.0.29            This bundle provides a way...
sensio/generator-bundle              v2.5.3             This bundle generates code...
stripe/stripe-php                    v3.23.0            Stripe PHP Library
swiftmailer/swiftmailer              v5.4.9             Swiftmailer, free feature-...
symfony/assetic-bundle               v2.8.2             Integrates Assetic into Sy...
symfony/monolog-bundle               v2.12.1            Symfony MonologBundle
symfony/polyfill-intl-icu            v1.7.0             Symfony polyfill for intl'...
symfony/polyfill-mbstring            v1.7.0             Symfony polyfill for the M...
symfony/polyfill-php54               v1.7.0             Symfony polyfill backporti...
symfony/polyfill-php55               v1.7.0             Symfony polyfill backporti...
symfony/polyfill-php56               v1.7.0             Symfony polyfill backporti...
symfony/polyfill-php70               v1.7.0             Symfony polyfill backporti...
symfony/polyfill-util                v1.7.0             Symfony utilities for port...
symfony/security-acl                 v2.8.0             Symfony Security Component...
symfony/swiftmailer-bundle           v2.6.7             Symfony SwiftmailerBundle
symfony/symfony                      v2.8.0             The Symfony PHP framework
twig/extensions                      v1.5.1             Common additional features...
twig/twig                            v1.35.0            Twig, the flexible, fast, ...
willdurand/jsonp-callback-validator  v1.1.0             JSONP callback validator.

我已经研究了几个小时了,但我还没有找到关于这个错误的有用信息。

提前谢谢。

EN

回答 1

Stack Overflow用户

发布于 2018-02-17 18:02:52

问题出在您的控制器上。可能它们扩展了Symfony\Component\ DependencyInjection\ContainerAware,后者从2.8版起就不推荐使用了。删除它并使用Symfony\ Component\DependencyInjection\ ContainerAwareTrait

代码语言:javascript
复制
use Symfony\Component\DependencyInjection\ContainerAwareInterface; 
use Symfony\Component\DependencyInjection\ContainerAwareTrait;

class MyBundleController implements ContainerAwareInterface { 
    use ContainerAwareTrait; 
    /** 
    * @Route("/", name="_index") 
    * @Template() 
    */ 
    public function indexAction() { 
            var_dump($this->container); 
            return array(); 
    }
}

编辑: Cerad在评论中是正确的:

不需要重写从控制器扩展而来的现有控制器。问题出在像FOSUserBundle这样的第三方包中,这些包不能从控制器扩展。然而,即使它们仍然应该在2.8以下工作,或者至少给出不同的错误。

无论在哪种情况下,它都应该可以工作。

参考文献:

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48837362

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档