Symfony - problem z konfiguracją restowego api.

0

Cześć!
Chciałem pobawić się trochę w symfony, ale niestety poległem przy konfiguracji.
Mianowicie przez composera dodałem FOSRestController i JMSSerialize. Następnie przez

bin/console generate:bundle

wygenerowałem bundla.
Następnie w src/ApiBundle/Resources/config/routing.yml dodałem:

Api:
    resource: "@api/Controller/ApiController.php"
    prefix: /api/
    type: rest

A w app/config/config.yml:

fos_rest:
    body_listener: true
    format_listener:
        rules:
            - { path: '^/', priorities: ['json'], fallback_format: json, prefer_extension: false }
    param_fetcher_listener: true
    view:
        view_response_listener: 'force'
        formats:
            json: true

Plik src/ApiBundle/Controller/ApiController.php zawiera:

<?php

namespace ApiBundle\Controller;

use FOS\RestBundle\Controller\FOSRestController;

class ApiController extends FOSRestController {

    public function optionsApiAction() {

    }

    public function getUserAction() {

    	$data = array(
    		'type' => 'asd',
    		'asd' => 'pbk',

    	);

    	$this->view($data, 200);

    	return $this->handleView($view);

    }

}

Niestety ciągle dostaję komunikat:

Bundle "api" does not exist or it is not enabled. Maybe you forgot to add it in the registerBundles() method of your AppKernel.php file? in @Api/Controller/ApiController.php (which is being imported from "/var/www/html/api/src/ApiBundle/Resources/config/routing.yml"). Make sure the "api" bundle is correctly registered and loaded in the application kernel class. If the bundle is registered, make sure the bundle path "@Api/Controller/ApiController.php" is not empty.

Czy ktoś bardziej doświadczony z tym frameworkiem mógłby podpowiedzieć co robię źle?

0

Maybe you forgot to add it in the registerBundles() method of your AppKernel.php file?

0

Dokładnie jak kolega wyżej. Zarejestruj bundla w pliku AppKernel.

0

Jest zarejestrowany.

public function registerBundles()
    {
        $bundles = [
            new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
            new Symfony\Bundle\SecurityBundle\SecurityBundle(),
            new Symfony\Bundle\TwigBundle\TwigBundle(),
            new Symfony\Bundle\MonologBundle\MonologBundle(),
            new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
            new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
            new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
            new FOS\RestBundle\FOSRestBundle(),
            new JMS\SerializerBundle\JMSSerializerBundle(),
            new AppBundle\AppBundle(),
            new ApiBundle\ApiBundle(),
        ];

        if (in_array($this->getEnvironment(), ['dev', 'test'], true)) {
            $bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
            $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
            $bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
            $bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
        }

        return $bundles;
    }

Gdyby w tym leżał problem to nie leciał bym na forum :D

1 użytkowników online, w tym zalogowanych: 0, gości: 1