2

我正在尝试版本中的FOSRestful示例,Symfony 2但出现以下错误

无法从“/Library/WebServer/Documents/symfony/app/config/routing_dev.yml”导入资源“@AcmeDemoBundle/Controller/UsersController”。确保“AcmeDemoBundle”包已正确注册并加载到应用程序内核类中。

因为我是新手所以我不知道 FOSRestfulBundle 是否安装正确所以我在这里发布所有步骤

到目前为止,我已经完成了以下设置

1. 在AppKernel.php

 new JMS\SerializerBundle\JMSSerializerBundle(),
 new FOS\RestBundle\FOSRestBundle(),

2. 在作曲家.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"
        }
    }


}
4

1 回答 1

0

我已经通过将.php扩展附加到UsersControllerin来解决它routing_dev.yml

所以正确的输入是

resource: "@AcmeDemoBundle/Controller/UsersController.php"    
于 2013-04-15T16:55:18.690 回答