小编Inv*_*tus的帖子

Symfony 4:事件监听器无法自动装配UserInterface


当我将UserInterface添加到我的事件监听器时,我有以下错误:

Cannot autowire service "App\EventListener\ControllerListener": argument "$user" of method "__construct()" references interface "Symfony\Component\Security\Core\User\UserInterface" but no such service exists. It cannot be auto-registered because it is from a different root namespace.
Run Code Online (Sandbox Code Playgroud)


我不知道发生了什么,其他服务工作正常.你能找代码并告诉我我做错了什么吗?

〜SRC /事件监听/ ControllerListener.php

<?php
namespace App\EventListener;

use App\Entity\User;
use App\Entity\DailyWin;
use App\Controller\DailyWinController;
use Psr\Log\LoggerInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;

class ControllerListener extends Controller implements DailyWinController
{
    private $authChecker, $user, $logger;

    public function __construct(UserInterface $user, AuthorizationCheckerInterface $authChecker, LoggerInterface $logger) {
        $this->user = $user;
        $this->authChecker = $authChecker;
        $this->logger …
Run Code Online (Sandbox Code Playgroud)

php symfony symfony4

4
推荐指数
1
解决办法
2612
查看次数

Symfony Doctrine无法找到要加载的灯具

我从Symfony(3.4)开始,我有负载夹具的问题.
当我执行php bin/console doctrine:fixtures:load然后我得到消息:

In LoadDataFixturesDoctrineCommand.php line 95:
  Could not find any fixture services to load.

有我的代码:

〜/ SRC /的appbundle/DataFixtures/ORM/LoadUserData.php

namespace AppBundle\DataFixtures\ORM;

use Doctrine\Common\DataFixtures\FixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

class LoadUserData implements FixtureInterface, ContainerAwareInterface {

    private $container;

    /**
     * Load data fixtures with the passed EntityManager
     *
     * @param ObjectManager $manager
     */
    public function load(ObjectManager $manager)
    {
        $user = new User();
        $user->setLogin('admin');
        $user->setEmail('admin@admin.admin');
        $encoder = $this->container->get('security.password_encoder');
        $password = $encoder->encodePassword($user, '123qwe');
        $user->setPassword($password);

        $manager->persist();
        $manager->flush();
    }

    public function setContainer(ContainerInterface …
Run Code Online (Sandbox Code Playgroud)

php orm doctrine symfony doctrine-orm

1
推荐指数
1
解决办法
1741
查看次数

Symfony 4.0不起作用

关键点:
- 我在symfony 4.0上创建了新项目:composer create-project symfony/skeleton sf4
- 欢迎页面正在运行
- 我想用https://symfony.com/doc/current/page_creation.html创建我的第一页, 我完全按照他们的说法做了:创建控制器和路由
- 欢迎页面更改状态为:No route found for "GET /" <
- 已解决 - 新页面路径找不到文件 - 错误404

我究竟做错了什么?那很傻

~src/Controller/SecurityController.php

<?php
namespace App\Controller;

use Symfony\Component\HttpFoundation\Response;

class SecurityController {
    public function logowanie() {
        return new Response(
            '<html><body>Logowanie</body></html>'
        );
    }
}
Run Code Online (Sandbox Code Playgroud)


〜配置/ routes.yaml

index:
    path: /
    controller: App\Controller\MainController::index

logowanie:
    path: /logowanie
    controller: App\Controller\SecurityController::logowanie
Run Code Online (Sandbox Code Playgroud)

编辑:
主页工作 - 谢谢@Cerad

php symfony symfony4

1
推荐指数
1
解决办法
3930
查看次数

标签 统计

php ×3

symfony ×3

symfony4 ×2

doctrine ×1

doctrine-orm ×1

orm ×1