php - “捆绑”应用程序“不存在或未启用
问题描述
GETing 时出现此错误{{url}}/api/user/me
:
在渲染模板期间抛出异常(“Bundle >”App”不存在或未启用。也许你忘记在你的 App\Kernel.php 文件的 >registerBundles() 方法中添加它?在@App/Controller/UserController(从“....\config/routes.yaml”导入)确保>确保“App/Controller/UserController”包已正确注册并>加载到应用程序内核类中。如果捆绑包已注册,请确保 > 捆绑包路径“@App/Controller/UserController”不为空。”)。
我正在使用 FOSRestBundle 和 FOSOauthBundle。
路线.yml
app_api:
resource: "@App/Controller/UserController"
type: annotation
捆绑包.php
<?php
return [
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle::class => ['all' => true],
Doctrine\Bundle\DoctrineCacheBundle\DoctrineCacheBundle::class => ['all' => true],
Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true],
Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class => ['all' => true],
Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true],
Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle::class => ['all' => true],
Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true],
Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true],
Symfony\Bundle\MonologBundle\MonologBundle::class => ['all' => true],
Symfony\Bundle\DebugBundle\DebugBundle::class => ['dev' => true, 'test' => true],
Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true],
Symfony\Bundle\WebServerBundle\WebServerBundle::class => ['dev' => true],
Nelmio\CorsBundle\NelmioCorsBundle::class => ['all' => true],
Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle::class => ['dev' => true, 'test' => true],
Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle::class => ['all' => true],
FOS\OAuthServerBundle\FOSOAuthServerBundle::class => ['all' => true],
FOS\RestBundle\FOSRestBundle::class => ['all' => true],
JMS\SerializerBundle\JMSSerializerBundle::class => ['all' => true],
Nelmio\ApiDocBundle\NelmioApiDocBundle::class => ['all' => true],
FOS\UserBundle\FOSUserBundle::class => ['all' => true]
];
用户控制器
<?php
namespace App\Controller;
use App\Entity\User;
use App\Service\UserService;
use FOS\RestBundle\Controller\AbstractFOSRestController;
use FOS\RestBundle\Routing\ClassResourceInterface;
use FOS\RestBundle\View\View;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use FOS\RestBundle\Controller\Annotations\RouteResource;
use FOS\RestBundle\Controller\Annotations as Rest;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
/**
* @RouteResource("User")
*/
class UserController extends AbstractFOSRestController implements ClassResourceInterface
{
/**
* @var TokenStorageInterface
*/
private $tokenStorage;
/**
* @param TokenStorageInterface $tokenStorage
*/
public function __construct(TokenStorageInterface $tokenStorage)
{
$this->tokenStorage = $tokenStorage;
}
/**=
* @Route("/api/user/me")
* @Method("GET")
*
* @return User|string
*/
public function getMeAction()
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
$loggedInUser = $this->tokenStorage->getToken()->getUser();
return new Response($loggedInUser);
}
作曲家.json
...
"autoload": {
"psr-4": {
"App\\": "src/"
}
},
...
解决方案
@App/...
带有“at”符号的符号纯粹用于解析捆绑包的位置。
您正在尝试解析不在捆绑包中的项目源文件的位置。
试试routes.yml
这个:
app_api:
resource: "../src/Controller/*"
type: annotation
推荐阅读
- error-handling - 禁用 Flutter 的“死机红屏”
- elasticsearch - 如何在 Elasticsearch 中为关键字类型的文本字段配置映射?
- awk - 算术运算后函数的应用
- python-3.x - 使用 numpy 进行有效矩阵切片
- javascript - 如何在同一模块内调用函数
- java - 使用带有 RestHighLevelClient 的 Basic-Auth-Proxy 后面的 ElasticSearch 端点
- google-app-engine - Flask 无法读取应该在 main.py 旁边的文件,该文件检索了 Flask Config 的环境变量
- java - android.widget.Button 没有 setOnClickListener 方法
- c - 从 C 中的文件读取 - 错误的输出
- jquery - 有没有办法让我的 cookie 弹出几秒钟的延迟?