0

I am building an api bundle for sulu but when im configuring routes to my controller i get the error 'The controller for URI "/ovio" is not callable: Controller "ovio.controller" does neither exist as service nor as class.'

What am i doing wrong here?

# sulu application -> config/routes_websites.yaml
ovio_bundle:
    path: /ovio
    defaults:
        _controller: ovio.controller
// My Bundle -> OvioController.php
namespace DigitalWeb\Bundle\OvioBundle\Controller;

use DigitalWeb\Bundle\OvioBundle\Interface\OvioInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Request;


#[Route('/ovio', name: 'api_')]
class ProjectController extends AbstractController
{
    #[Route('/api', name: 'api')]
    public function index(OvioInterface $OvioInterface): JsonResponse
    {
        $response = $OvioInterface->api_call($this->getParameter('api_key'));

        $json = new JsonResponse();

        return $json->fromJsonString($response);
    }

    #[Route('/api/{license}', name: 'api_license')]
    public function indexVehicle(OvioInterface $OvioInterface, $license): JsonResponse
    {
        $request = Request::createFromGlobals();
        $response = $OvioInterface->api_call($this->getParameter('api_key'), $license, $request->query);


        $json = new JsonResponse();

        return $json->fromJsonString($response);
    }
}

<!-- My Bundle -> Resources/config/services.xml -->

<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://symfony.com/schema/dic/services
        http://symfony.com/schema/dic/services/services-1.0.xsd">

    
    <services>
        <service id="ovio.controller" class="DigitalWeb\Bundle\OvioBundle\Controller\OvioController" autowire="true"
                 public="true">
            <argument type="service" id="fos_rest.view_handler.default"/>
            <tag name="ovio.controller"/>
            <tag name="controller.service_arguments"/>
            <tag name="container.service_subscriber"/>
            <!-- <tag name="sulu.context" context="website"/> -->
        </service>
    </services>
</container>

  • Can you run the command "php bin/console debug:router" to get the route list where to check this route ? – Viraj Amarasinghe Mar 12 '23 at 17:30
  • Trying to define two routes with the same path `/ovio/` seldom ends well. – Cerad Mar 12 '23 at 18:12
  • It's `/ovio/api`, you have defined the class `/ovio` then the controller is `/api`. – Bossman Mar 12 '23 at 20:06
  • Did you create an extension which loads the config in `Resources/config/services.xml`? – dbrumann Mar 12 '23 at 22:13
  • In Sulu `bin/console debug:router` shows only the admin routes. You need to use the `bin/websiteconsole debug:router` to show your website routes. Also use the `debug:container` command to check if your service is correctly registered. – Alexander Schranz Mar 13 '23 at 09:30
  • When I execute the `bin/websiteconsole debug:router` command /ovio is returned with `ovio_bundle ANY ANY ANY /ovio ` – Roan Meijer Mar 13 '23 at 18:51
  • @Bossman When I go to `/ovio/api/` I get the error `No route found for "GET https://localhost:8000/ovio/api/"` – Roan Meijer Mar 13 '23 at 18:54
  • @dbrumann Yes, I did create an extension which loads the config. `class OvioExtension extends Extension { public function load(array $configs, ContainerBuilder $container) { $loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); $loader->load('services.xml'); } }` – Roan Meijer Mar 13 '23 at 19:17
  • 1
    @RoanMeijer, it looks like your tag might not be registering, you can check with `php bin/console debug:container --tags` and see if your tag `ovio.controller` is shown. What version of Symfony are you using? – Bossman Mar 13 '23 at 22:04
  • @Bossman You're right the tag `ovio.controller` does not exist. I'm using symfony 6.2.7. – Roan Meijer Mar 14 '23 at 17:40
  • @RoanMeijer, From Symfony 6.1, it uses the [AbstractBundle](https://symfony.com/blog/new-in-symfony-6-1-simpler-bundle-extension-and-configuration), you can load your config and set tags in the main file now rather than through the DependancyInjection Extension class. – Bossman Mar 14 '23 at 17:51

0 Answers0