2
我試圖在FOSRestful
例如Symfony 2
版本,但我得到以下錯誤無法使用的Symfony
無法從 導入資源「@ AcmeDemoBundle /控制器/ UsersController」 「/庫FOSRestful找到控制器/WebServer/Documents/symfony/app/config/routing_dev.yml」。 確保「AcmeDemoBundle」包已正確註冊,並且在應用程序內核類中加載了 。
,因爲我是新來的,所以我不知道是否被安裝正確所以這裏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"
}
}
}
你可以顯示你的composer.json文件嗎?這可能是Acme的命名空間不正確。 – Sgoettschkes
@Sgoettschkes請參閱更新! – Hunt