我已将我的Symfony项目从2.6升级到2.8,之后,当我请求配置文件视图时,我收到错误500。错误是:
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时,我会看到下一个列表:
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.
我一直在研究几个小时,但我还没找到有关此错误的有用信息。
提前致谢。
答案 0 :(得分:1)
问题出在您的控制器中。可能它们扩展了自2.8版以来不推荐使用的Symfony \ Component \ DependencyInjection \ ContainerAware。删除它并使用 Symfony \ Component \ DependencyInjection \ ContainerAwareTrait 。
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();
}
}
参考文献:ref 1