Symfony既指用于构建Web应用程序的PHP框架,也指构建框架的一组组件。此标记指的是当前支持的主要版本2.x,3.x和4.x.或者,您可以使用相应的标记指定确切的版本。此标记不应用于有关Symfony 1.x的问题。请改用Symfony1标签。
控制器无法从容器中获取,因为它是私有的。您是否忘记使用“controller.service_arguments”标记服务?
我创建了这个控制器 我创建了这个控制器 <?php namespace App\Controller; use App\Interface\GetDataServiceInterface; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; #[Route('/api')] class ApiController { private GetDataServiceInterface $getDataService; public function __construct(GetDataServiceInterface $getDataService) { $this->getDataService = $getDataService; } #[Route('/products', name: 'products', methods: ['GET'])] public function products(): Response { return new Response( $this->getDataService->getData() ); } } 然后我在 services.yml 上设置了 GetDataServiceInterface 的自动装配 parameters: services: # default configuration for services in *this* file _defaults: autowire: true # Automatically injects dependencies in your services. autoconfigure: true # Automatically registers your services as commands, event subscribers, etc. # makes classes in src/ available to be used as services # this creates a service per class whose id is the fully-qualified class name App\: resource: '../src/' exclude: - '../src/DependencyInjection/' - '../src/Entity/' - '../src/Kernel.php' App\Service\GetJsonDataService: ~ App\Interface\GetDataServiceInterface: '@App\Services\GetJsonDataService' 这是界面 <?php namespace App\Interface; interface GetDataServiceInterface { public function getData():string; } 和服务 <?php namespace App\Service; use App\Interface\GetDataServiceInterface; class GetJsonDataService implements GetDataServiceInterface { public function getData():string { return getcwd(); } } 但是现在当我尝试提出请求时出现此错误 The controller for URI "/api/products" is not callable: Controller "App\Controller\ApiController" cannot be fetched from the container because it is private. Did you forget to tag the service with "controller.service_arguments"? 我不确定还需要设置什么 您的控制器不会扩展 AbstractController,因此您必须在 controller.service_arguments 中手动将其标记为 services.yaml,或使用 #[AsController] 属性 https://symfony.com/doc/current/controller/service.html 除了 bechir 的答案之外,还要确保您在课程文档顶部使用 namespace App\Controller;。如果没有它,它会抛出这个错误。
我正在尝试对请求实施 symfony 验证资产。 我正在将表单数据从邮递员传递到控制器中的路线。 #[路由(路径: '/test', 名称: 'test', 方法: 'GET')] 公开
Symfony 上的 App\Todo\Application\Command\CreateTodoCommand
我有这个命令 我有这个命令 <?php namespace App\Todo\Application\Command; use Ramsey\Uuid\Uuid; use Ramsey\Uuid\UuidInterface; class CreateTodoCommand { public function __construct( private string $name, private string $text, private string $userId ) { } public function getName(): string { return $this->name; } public function getText(): string { return $this->text; } public function getUserId(): UuidInterface { return Uuid::fromString($this->userId); } } 还有这个处理程序 <?php namespace App\Todo\Application\Command; use App\Todo\Application\Interfaces\CommandHandlerInterface; use App\Todo\Domain\Entity\Todo; use App\Todo\Domain\Repository\TodoRepositoryInterface; use App\Todo\Domain\ValueObject\Name; use App\Todo\Domain\ValueObject\Text; use App\Todo\Domain\ValueObject\UserId; use Ramsey\Uuid\Uuid; class CreateTodoCommandHandler implements CommandHandlerInterface { public function __construct(private TodoRepositoryInterface $todoRepository) {} public function __invoke(CreateTodoCommand $command) { $todo = new Todo( Uuid::uuid4(), new Name($command->getName()), new Text($command->getTe xt()), new UserId($command->getUserId()) ); $this->todoRepository->save($todo); } } 这个messenger.yaml配置 framework: messenger: # Uncomment this (and the failed transport below) to send failed messages to this transport for later handling. # failure_transport: failed transports: # https://symfony.com/doc/current/messenger.html#transport-configuration async: dsn: '%env(RABBITMQ_DSN)%' retry_strategy: max_retries: 5 delay: 1000 multiplier: 2 max_delay: 60000 # failed: 'doctrine://default?queue_name=failed' # sync: 'sync://' routing: # Route your messages to the transports # 'App\Message\YourMessage': async 'App\Todo\Application\Command\CreateTodoCommand': async 还有这个services.yaml配置 # This file is the entry point to configure your own services. # Files in the packages/ subdirectory configure your dependencies. # Put parameters here that don't need to change on each machine where the app is deployed # https://symfony.com/doc/current/best_practices.html#use-parameters-for-application-configuration parameters: services: # default configuration for services in *this* file _defaults: autowire: true # Automatically injects dependencies in your services. autoconfigure: true # Automatically registers your services as commands, event subscribers, etc. # Registra el repositorio como servicio App\Todo\Infrastructure\Repository\DoctrineTodoRepository: arguments: $em: '@doctrine.orm.entity_manager' # Registra el handler y autowire la interfaz con su implementación App\Todo\Application\Command\CreateTodoCommandHandler: arguments: $todoRepository: '@App\Todo\Infrastructure\Repository\DoctrineTodoRepository' # makes classes in src/ available to be used as services # this creates a service per class whose id is the fully-qualified class name App\: resource: '../src/' exclude: - '../src/DependencyInjection/' - '../src/Entity/' - '../src/Kernel.php' # add more service definitions when explicit configuration is needed # please note that last definitions always *replace* previous ones 但是当我尝试使用排队的消息时,我收到此错误 messenger.CRITICAL: Error thrown while handling message App\Todo\Application\Command\CreateTodoCommand. Removing from transport after 5 retries. Error: "No handler for message "App\Todo\Application\Command\CreateTodoCommand"." {"class":"App\\Todo\\Application\\Command\\CreateTodoCommand","retryCount":5,"error":"No handler for message \"App\\Todo\\Application\\Command\\CreateTodoCommand\".","exception":"[object] (Symfony\\Component\\Messenger\\Exception\\NoHandlerForMessageException(code: 0): No handler for message \"App\\Todo\\Application\\Command\\CreateTodoCommand\". at /var/www/html/vendor/symfony/messenger/Middleware/HandleMessageMiddleware.php:117)"} [] 如果我用 bin/console debug:messenger 检查处理程序,列表中没有 CreateTodoCommandHandler Messenger ========= messenger.bus.default --------------------- The following messages can be dispatched: ---------------------------------------------------------- Symfony\Component\Process\Messenger\RunProcessMessage handled by process.messenger.process_message_handler Symfony\Component\Console\Messenger\RunCommandMessage handled by console.messenger.execute_command_handler Symfony\Component\Messenger\Message\RedispatchMessage handled by messenger.redispatch_message_handler ---------------------------------------------------------- 我多次清除缓存 我认为配置是正确的,但无法设置处理程序,有问题还是我错过了什么? 您已经在构造函数方法之外声明了这些变量 class CreateTodoCommand { private string $name, private string $text, private string $userId public function __construct( ) { }
方法 setSQLLogger 已弃用 - Doctrine\DBAL\Configuration
我正在将应用程序从 Symfony 5.4 升级到 Symfony 6.0。一路上,我不得不升级一些学说库。 我们目前使用 setSQLLogger(null) 来避免 SQL
#[AsEventListener(event: OAuth2Events::TOKEN_REQUEST_RESOLVE)] 无法按预期工作
按照链接https://github.com/thephpleague/oauth2-server-bundle/blob/master/docs/listening-to-league-events.md#listening-to-league-oauth-server-events我为 OAuth2 注册了一个监听器...
Dropdown 不起作用,i.createPopper 不是函数
我正在使用 Symfony 7 开发一个使用 Bootstrap 5.3 的网站。到目前为止,除了下拉菜单之外,一切都运行良好。我的代码中有以下下拉菜单: 我正在使用 Symfony 7 开发一个使用 Bootstrap 5.3 的网站。到目前为止,除了下拉菜单之外,一切都运行良好。我的代码中有以下下拉菜单: <li class="nav-item dropdown"> <a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false"> Dropdown link </a> <ul class="dropdown-menu"> <li><a class="dropdown-item" href="#">Action</a></li> <li><a class="dropdown-item" href="#">Another action</a></li> <li><a class="dropdown-item" href="#">Something else here</a></li> </ul> </li> 当我单击它时,它没有显示任何内容并在控制台中记录此错误: 未捕获类型错误:i.createPopper 不是函数 我使用 AssetMapper 安装了 Bootstrap。这是我的 importmap.php 文件: <?PHP return [ 'app' => [ 'path' => './assets/app.js', 'entrypoint' => true, ], '@hotwired/stimulus' => [ 'version' => '3.2.2', ], '@symfony/stimulus-bundle' => [ 'path' => './vendor/symfony/stimulus-bundle/assets/dist/loader.js', ], '@hotwired/turbo' => [ 'version' => '7.3.0', ], '@popperjs/core' => [ 'version' => '2.11.8', ], 'bootstrap' => [ 'version' => '5.3.3', ], 'bootstrap/dist/css/bootstrap.min.css' => [ 'version' => '5.3.3', 'type' => 'css', ], 'bootstrap/dist/js/bootstrap.min.js' => [ 'version' => '5.3.3', ], 'bootstrap-icons/font/bootstrap-icons.min.css' => [ 'version' => '1.11.3', 'type' => 'css', ], '@fortawesome/fontawesome-free/css/all.css' => [ 'version' => '6.7.2', 'type' => 'css', ] ]; 还有我的 app.js: import './bootstrap.js'; /* * Welcome to your app's main JavaScript file! * * This file will be included onto the page via the importmap() Twig function, * which should already be in your base.html.twig. */ import './styles/app.css'; // Import Popper.js import '@popperjs/core'; // Import everything related to Bootstrap import 'bootstrap/dist/css/bootstrap.min.css'; import 'bootstrap/dist/js/bootstrap.min.js'; import 'bootstrap-icons/font/bootstrap-icons.min.css'; // Import font awesome import '@fortawesome/fontawesome-free/css/all.css'; console.log('This log comes from assets/app.js - welcome to AssetMapper! 🎉'); 我找到了解决方案。我们需要使用 bootstrap.bundle.min.js。 导入地图.php: 'bootstrap/dist/js/bootstrap.bundle.min.js' => [ 'version' => '5.3.3', ], app.js: import 'bootstrap/dist/js/bootstrap.bundle.min.js';
Symfony 7、Bootstrap 5.3 - 下拉菜单不起作用,i.createPopper 不是函数
我正在使用 Symfony 7 开发一个使用 Bootstrap 5.3 的网站。到目前为止,除了下拉菜单之外,一切都运行良好。我的代码中有以下下拉菜单: 我正在使用 Symfony 7 开发一个使用 Bootstrap 5.3 的网站。到目前为止,除了下拉菜单之外,一切都运行良好。我的代码中有以下下拉菜单: <li class="nav-item dropdown"> <a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false"> Dropdown link </a> <ul class="dropdown-menu"> <li><a class="dropdown-item" href="#">Action</a></li> <li><a class="dropdown-item" href="#">Another action</a></li> <li><a class="dropdown-item" href="#">Something else here</a></li> </ul> </li> 当我单击它时,它不显示任何内容并在控制台中记录此错误:Uncaught TypeError: i.createPopper is not a function 我使用 AssetMapper 安装了 Bootstrap。这是我的 importmap.php 文件: <?PHP return [ 'app' => [ 'path' => './assets/app.js', 'entrypoint' => true, ], '@hotwired/stimulus' => [ 'version' => '3.2.2', ], '@symfony/stimulus-bundle' => [ 'path' => './vendor/symfony/stimulus-bundle/assets/dist/loader.js', ], '@hotwired/turbo' => [ 'version' => '7.3.0', ], '@popperjs/core' => [ 'version' => '2.11.8', ], 'bootstrap' => [ 'version' => '5.3.3', ], 'bootstrap/dist/css/bootstrap.min.css' => [ 'version' => '5.3.3', 'type' => 'css', ], 'bootstrap/dist/js/bootstrap.min.js' => [ 'version' => '5.3.3', ], 'bootstrap-icons/font/bootstrap-icons.min.css' => [ 'version' => '1.11.3', 'type' => 'css', ], '@fortawesome/fontawesome-free/css/all.css' => [ 'version' => '6.7.2', 'type' => 'css', ] ]; 还有我的 app.js: import './bootstrap.js'; /* * Welcome to your app's main JavaScript file! * * This file will be included onto the page via the importmap() Twig function, * which should already be in your base.html.twig. */ import './styles/app.css'; // Import Popper.js import '@popperjs/core'; // Import everything related to Bootstrap import 'bootstrap/dist/css/bootstrap.min.css'; import 'bootstrap/dist/js/bootstrap.min.js'; import 'bootstrap-icons/font/bootstrap-icons.min.css'; // Import font awesome import '@fortawesome/fontawesome-free/css/all.css'; console.log('This log comes from assets/app.js - welcome to AssetMapper! 🎉'); 我找到了解决方案。我们需要使用 bootstrap.bundle.min.js。 导入地图.php: 'bootstrap/dist/js/bootstrap.bundle.min.js' => [ 'version' => '5.3.3', ], app.js: import 'bootstrap/dist/js/bootstrap.bundle.min.js';
composer 更新在使用自定义值时不断覆盖parameters.yml
我的parameters.yml中有一些自定义条目,每次运行composer更新时,它都会添加缺少的条目,这更糟糕的是会覆盖我的自定义条目。 我怎样才能阻止这个? 例如...
我正在尝试在 nginx 上设置 symfony。 以下是配置 - 上游 phpfcgi { 服务器127.0.0.1:9000; # 服务器unix:/var/run/php5-fpm.sock; #for PHP-FPM 在 UNIX 套接字上运行 } ...
我尝试使用 Vue 和 Symfony 创建一个项目。 我使用树枝模板作为单页应用程序的主页。 我无法使用引导程序图标中的字体,因为路径不正确。 任何人都有想法...
symfony/validator:如何将字符串验证为 int
我在 Symfony 中创建了一个控制器来处理 API 请求。我想验证操作请求。请求的参数“type”必须是整数。有控制器动作代码: 公共职能
Symfony JsonResponse 将snake_case 属性转换为CamelCase
我是 symfony 的新手,正在尝试构建一个 json API。 我正在尝试返回一个名为 User 的 Doctrine 生成实体,作为对其中一个端点的响应。但是,当将实例传递给 json 时
Symfony / api 平台 PATCH NotEncodableValueException:“语法错误”
我使用 api 平台,GET 和 POST 工作正常,我需要在我的实体中修补 isFinished 但出现错误: 请求未捕获的 PHP 异常 Symfony\Component\Serializer\Exception\NotEncodableValueExce...
我有一个通过以下方式与用户实体相关的评论实体 #[ORM\ManyToOne(targetEntity: User::class, inversedBy: '评论')] 私人用户$user; 当尝试像这样保存它时: $评论...
我正在根据面试表计算平均评分,并在候选人表中显示平均评分。 Symfony 给出未定义的方法错误
我正在根据面试表计算平均评分,并在候选人表中显示平均评分。 Symfony 给出未定义的方法错误 $qb = $this->createQueryBuilder('c') ->
找不到“POST /login”的路由(来自“http://xx.net/authentication/signin”)
我在服务器上部署 Web 应用程序时遇到问题。我使用各种组件在 Symfony 中创建了一个 API,并使用 npm 在 Angular 中创建了一个客户端。它在我的本地机器上运行得很好,...
在 Symfony2 项目中,您可以在 app/config/parameters.ini 文件中配置数据库连接。文档指出您可以使用 sqlite3 PDO 驱动程序等。 但是配置...
我从 symfony 2 开始,我想用数据库中的数据显示“选择”类型,但我有一个问题: 添加动作: 公共函数addAction() { $categories = new CategoryAnnonce...
我想从路径为/api/slug/{slug}的API获取数据。我尝试使用提供者和控制器,但总是以以下错误结束: 标识符值或配置无效 ID 必须位于...
我正在 Symfony 6 应用程序中试验 PHP 枚举,我认为我找到了一个非常好的用例。一切正常,但 phpstan 一直抱怨我返回的类型。 ------ --...