我正在尝试FOSRestful
版本中的Symfony 2
示例,但我收到了以下错误
无法导入资源" @ AcmeDemoBundle / Controller / UsersController" 从 " /Library/WebServer/Documents/symfony/app/config/routing_dev.yml" ;. 确保" AcmeDemoBundle" bundle正确注册并且 在应用程序内核类中加载。
因为我是新手所以我不知道FOSRestfulBundle是否正确安装,所以我在这里发布所有步骤
直到现在我已经完成了以下设置
的事情 1。在AppKernel.php
new JMS\SerializerBundle\JMSSerializerBundle(), new FOS\RestBundle\FOSRestBundle(),
2。在composer.json中
"jms/serializer-bundle": "dev-master", "friendsofsymfony/rest-bundle": "dev-master"
3。在config.yml
中fos_rest: routing_loader: default_format: json
4。在routing_dev.yml
中users: type: rest resource: "@AcmeDemoBundle/Controller/UsersController" prefix: /users
5。以下是内部UsersController
的内容
Acme/DemoBundle/Controller
<?php
namespace Acme\DemoBundle\Controller;
use Acme\DemoBundle\Model\User;
use Acme\DemoBundle\Model\UserQuery;
use FOS\RestBundle\Controller\Annotations as Rest;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class UsersController
{
/**
* @Rest\View
*/
public function allAction()
{
$users = UserQuery::create()->find();
return array('users' => $users);
}
/**
* @Rest\View
*/
public function getAction($id)
{
$user = UserQuery::create()->findPk($id);
if (!$user instanceof User) {
throw new NotFoundHttpException('User not found');
}
return array('user' => $user);
}
}
?>
6 .composer.json
{
"name": "symfony/framework-standard-edition",
"description": "The \"Symfony Standard Edition\" distribution",
"autoload": {
"psr-0": { "": "src/" }
},
"require": {
"php": ">=5.3.3",
"symfony/symfony": "2.2.*",
"doctrine/orm": "~2.2,>=2.2.3",
"doctrine/doctrine-bundle": "1.2.*",
"twig/extensions": "1.0.*",
"symfony/assetic-bundle": "2.1.*",
"symfony/swiftmailer-bundle": "2.2.*",
"symfony/monolog-bundle": "2.2.*",
"sensio/distribution-bundle": "2.2.*",
"sensio/framework-extra-bundle": "2.2.*",
"sensio/generator-bundle": "2.2.*",
"jms/security-extra-bundle": "1.4.*",
"jms/di-extra-bundle": "1.3.*",
"jms/serializer-bundle": "dev-master",
"friendsofsymfony/rest-bundle": "dev-master"
},
"scripts": {
"post-install-cmd": [
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile"
],
"post-update-cmd": [
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile"
]
},
"config": {
"bin-dir": "bin"
},
"minimum-stability": "alpha",
"extra": {
"symfony-app-dir": "app",
"symfony-web-dir": "web",
"branch-alias": {
"dev-master": "2.2-dev"
}
}
}
答案 0 :(得分:0)
我已通过在.php
UsersController
扩展名附加到routing_dev.yml
来解决此问题
以便正确输入
resource: "@AcmeDemoBundle/Controller/UsersController.php"