Question

i am trying the FOSRestful example in Symfony 2 version but i am getting following error

Cannot import resource "@AcmeDemoBundle/Controller/UsersController" from "/Library/WebServer/Documents/symfony/app/config/routing_dev.yml". Make sure the "AcmeDemoBundle" bundle is correctly registered and loaded in the application kernel class.

as i am new to it so i dont know whether FOSRestfulBundle is being installed properly or not so here i am posting all the steps

till now i have done following things to set up

1 . in AppKernel.php

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

2 . in composer.json

"jms/serializer-bundle": "dev-master",
"friendsofsymfony/rest-bundle": "dev-master"

3 . in config.yml

fos_rest:
    routing_loader:
        default_format: json

4 . in routing_dev.yml

users:
    type:     rest
    resource: "@AcmeDemoBundle/Controller/UsersController"    
    prefix: /users

5 . following is the content of UsersController , which is inside 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"
        }
    }


}
Était-ce utile?

La solution

i have solved it by appending .php extension to UsersController in routing_dev.yml

so that correct entry is

resource: "@AcmeDemoBundle/Controller/UsersController.php"    
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top