Error extending CRUD Controller - new controller is not callable

2,491 views
Skip to first unread message

Hannah C

unread,
Jun 4, 2013, 7:16:32 AM6/4/13
to sonata...@googlegroups.com
Hi,

I am trying to extend the basic Sonata CRUD controller, in order to add a custom action.

I have extended the controller, told the Entity Admin to use it, but I am getting the following error:

The controller must be a callable (Array(0 => Object(Acme\AdminBundle\Controller\AddressAdminController), 1 => authoriseAction) given).

My controller code is:

<?php
// src/Acme/AdminBundle/Controller/AddressAdminController.php
 
namespace Acme\AdminBundle\Controller;
use Sonata\AdminBundle\Controller\CRUDController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
 
class AddressAdminController extends CRUDController
{
protected function authoriseAction($id)
{
return new Response('Hello '.$id);
}
}

 admin.yml:

sonata.admin.Address:
        class: Acme\AdminBundle\Sonata\AddressAdmin
        tags:
            - { name: sonata.admin, manager_type: orm, group: Company, label: "Address" }
        arguments:
            - ~
            - Acme\CompanyFinderBundle\Entity\Address
            - 'Acme'
        calls:
            - [ setTranslationDomain, [AcmeAdminBundle] ]

And in my AddressAdmin.php file I have this:

protected function configureRoutes(RouteCollection $collection)
{
$auth_options = array('_controller' => 'AcmeAdminBundle:AddressAdmin');
$collection->add('authorise', $this->getRouterIdParameter().'/authorise');

Any help would be much appreciated.

Cheers,
Hannah 

Cassiano Tartari

unread,
Jun 4, 2013, 7:34:02 AM6/4/13
to sonata-users
I'll make a little example how I do:

Company/MyBundle/Resources/config/services.yml

  sonata.admin.example:
    class: Company\MyBundle\Admin\ExampleAdmin
    arguments: [null, Company\MyBundle\Entity\EntityExample, 'CompanyMyBundle:ExampleAdmin'] #last parameter is the controller
    calls:
        - [ setSecurityContext, [ '@security.context' ] ]
        - [ setContainer, [ '@service_container' ] ]
    tags:
        - { name: sonata.admin, manager_type: orm, group: Group Name, label: Label Text }




Company/MyBundle/Controller/ExampleAdminController.php

<?php

namespace Company\MyBundle\Controller;

use Sonata\AdminBundle\Controller\CRUDController as Controller;

class ExampleAdminController extends Controller {
    public function exampleAction($id = null) {
       //your code
    }
}



Company/MyBundle/Admin/ExampleAdmin.php

<?php

namespace Company\MyBundle\Admin;

use Sonata\AdminBundle\Admin\Admin;
use Sonata\AdminBundle\Route\RouteCollection;

class ExampleAdmin extends Admin {
    protected function configureRoutes(RouteCollection $collection) {
        $collection->add('example', $this->getRouterIdParameter() . '/example-path');
    }
}


Cassiano Valle Tartari
MSc. Computer Engineer

Tel: +55.48.84474818
Email: fal...@cassianotartari.eng.br
Site: http://www.cassianotartari.eng.br

QR Code


--
You received this message because you are subscribed to the Google Groups "sonata-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonata-users...@googlegroups.com.
To post to this group, send email to sonata...@googlegroups.com.
Visit this group at http://groups.google.com/group/sonata-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

jrdn hannah

unread,
Jun 4, 2013, 7:40:44 AM6/4/13
to sonata...@googlegroups.com
Hi,

I've tried that, same error :(

Hannah

You received this message because you are subscribed to a topic in the Google Groups "sonata-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sonata-users/9xEJQj_dM_Y/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to sonata-users...@googlegroups.com.

Cassiano Tartari

unread,
Jun 4, 2013, 7:45:53 AM6/4/13
to sonata-users
The error is just this:

The controller must be a callable (Array(0 => Object(Acme\AdminBundle\Controller\AddressAdminController), 1 => authoriseAction) given).

?

Cassiano Valle Tartari
MSc. Computer Engineer

Tel: +55.48.84474818
Email: fal...@cassianotartari.eng.br
Site: http://www.cassianotartari.eng.br

QR Code


jrdn hannah

unread,
Jun 4, 2013, 7:46:35 AM6/4/13
to sonata...@googlegroups.com
Yep, only that

Cassiano Tartari

unread,
Jun 4, 2013, 7:48:50 AM6/4/13
to sonata-users
Sorry, I don't know what to do... What are the version of symfony and sonata that are you using? I have a huge project using Sonata Admin with a lot of controllers with specific actions and all work like I post

Cassiano Valle Tartari
MSc. Computer Engineer

Tel: +55.48.84474818
Email: fal...@cassianotartari.eng.br
Site: http://www.cassianotartari.eng.br

QR Code


Jakala

unread,
Jun 4, 2013, 1:37:11 PM6/4/13
to sonata...@googlegroups.com
hi guys:

I think the problem is in your sonata config:

sonata.admin.Address:
        class: Acme\AdminBundle\Sonata\AddressAdmin
        tags:
            - { name: sonata.admin, manager_type: orm, group: Company, label: "Address" }
        arguments:
            - null
            - Acme\CompanyFinderBundle\Entity\Address
            - AdminBundle:AcmeAdmin
        calls:
            - [ setTranslationDomain, [AcmeAdminBundle] ]


Maybe the controller must set as "AdminBundle:AcmeAdmin" insteads of "Acme" ??
other question: all my entities with sonataAdmin have the first argument set to NULL. (not ~). 

Cassiano Tartari

unread,
Jun 4, 2013, 1:41:40 PM6/4/13
to sonata-users
If I'm not wrong when you fill a field in yml with "~" the field will get the default value from the method, that probably is NULL, so both solutions are the same. And probably your code correction is right, I've just post how I do, I didn't check the Hannahs code.

Cassiano Valle Tartari
MSc. Computer Engineer

Tel: +55.48.84474818
Email: fal...@cassianotartari.eng.br
Site: http://www.cassianotartari.eng.br

QR Code


Raul Araya Tauler

unread,
Jun 19, 2013, 4:16:41 PM6/19/13
to sonata...@googlegroups.com
Check your action scope. In order for it to be callable it should be public:

public function authoriseAction($id) ...

Reply all
Reply to author
Forward
0 new messages