Troubleshooting "The controller for URI is not callable" error

You're defining your controller function as showUserAction while in the definition your saying it is show[Action].

Either change your route configuration

user_show:
    pattern:  /user/{id}
    defaults: { _controller: UserBundle:Default:showUser }
    requirements:
        id:  \d+

or change your controller signature

public function showAction($id)
{

See if this helps


The logical name UserBundle:Default:show refers to UserBunde\Controller\DefaultController::showAction you have a method called showUserAction.

Either change the method name to showAction or change the logical name to UserBundle:Default:showUser.


Although not relevant to the example given, this error can also be caused if the controller Action is not public


After big search, this worked for me:

1.- Create CRUDController

// src/Acme/DemoBundle/Controller/CRUDController.php

namespace Acme\DemoBundle\Controller;

use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Sonata\AdminBundle\Controller\CRUDController as Controller;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Inter\PimeBundle\Entity\Empresa;

class CRUDController extends Controller
{
    public function publicarAction($id)
    {
       //code here...
    }
}

2.- Create the service

# app/config/config.yml
services:
    ebtity.admin.service:
        class: Acme\DemoBundle\Admin\EntityAdmin
        tags:
            - { name: sonata.admin, manager_type: orm, group: group, label: label }
        arguments:
            - NULL
            - Acme\DemoBundle\Entity\Entity
            - AcmeDemoBundle:EntityAdmin

3.- Create the template for the action button

{# src/Acme/DemoBundle/Resources/views/CRUD/list__action_publicar.html.twig #}

<a class="btn btn-sm" href="{{ admin.generateObjectUrl('publicar', object) }}">Publicar</a>

4.- Configure route

// src/Acme/DemoBundle/Admin/EntityAdmin.php

namespace Acme\DemoBundle\Admin;

// ...

use Sonata\AdminBundle\Route\RouteCollection;

class EntityAdmin extends Admin
{
     // ...

    protected function configureListFields(ListMapper $listMapper)
    {
        $listMapper
            ->addIdentifier('name')
            ->add('engine')
            ->add('rescueEngine')
            ->add('createdAt')
            ->add('_action', 'actions', array(
                'actions' => array(
                    'publicar' => array(
                        'template' => 'AcmeDemoBundle:CRUD:list__action_publicar.html.twig'
                    )
                )
            ));
    }

    protected function configureRoutes(RouteCollection $collection)
    {
        $collection
                ->add('publicar', 
                    $this->getRouterIdParameter().'/publicar',
                    array('_controller' => 'AcmeDemoBundle:CRUD:publicar')    
                );
    }
}

5.- Clear cache

Hope it helps

Tags:

Routes

Symfony