Sonata Admin Bundle configureRoutes getPersistentParameters

Denis Gimenez

I'm quite new at Sonata. I have a proyect that involves Clients and Loans. In ClientsAdmin.php i have configured the configureRoutes and getPersistentParameters functions

protected function configureRoutes(RouteCollection $collection)
{
    $collection->add('transacciones','transacciones/{id}');
}
public function getPersistentParameters()
{
    if (!$this->getRequest()) {
        return array();
    }

    return array(
        'id'  => $this->getRequest()->get('id'),
    );
} 

Also, i have override the CRUDController (and service.yml)

//service.yml

financiera.admin.clientes:
    class: BitsMkt\FinancieraBundle\Admin\ClientesAdmin
    arguments: [ ~,BitsMkt\FinancieraBundle\Entity\Clientes,FinancieraBundle:ClientesCRUD]
    tags:
        - {name: sonata.admin, manager_type: orm, group: Sistema, label: Clientes}



//ClientesCRUDController.php
namespace Bitsmkt\FinancieraBundle\Controller;

use Sonata\AdminBundle\Controller\CRUDController;

class ClientesCRUDController extends CRUDController
{
    public function transaccionesAction($id = null)
    {
        //throw new \RuntimeException('The Request object has not been set ' . $id);

        if (false === $this->admin->isGranted('LIST')) {
            throw new AccessDeniedException();
        }
        $id = $this->get('request')->get($this->admin->getIdParameter());

        if ($id == '*') {
            # TODOS - Viene de Dashboard

        }else
        {

            $object = $this->admin->getObject($id);

            if (!$object) {
                throw new NotFoundHttpException(sprintf('unable to find the object with id : %s', $id));
            }

            $this->admin->setSubject($object);            
        }


        $datagrid = $this->admin->getDatagrid();
        $formView = $datagrid->getForm()->createView();

        // set the theme for the current Admin Form
        $this->get('twig')->getExtension('form')->renderer->setTheme($formView, $this->admin->getFilterTheme());

        return $this->render('FinancieraBundle:Frontend:prestamos_clientes.html.twig', array(
            'action'     => 'list',
            'form'       => $formView,
            'datagrid'   => $datagrid,
            'csrf_token' => $this->getCsrfToken('sonata.batch'),
        ));


    }
}

The prestamos_clientes.html.twig view, shows the Clients and Loans info.

QUESTION: I want to filter the list view that i created (transaccionesAction) with an $id parameter and see the loans of an particular client.

Thanks.

11mb

You can set an admin to be the child of another. This has the advantage that you can, for example, click from one specific client to a list of loans for that particular clients..

To do this, follow the minimalistic documentation on the subject on setting an admin as child-admin: https://sonata-project.org/bundles/admin/master/doc/reference/architecture.html#create-child-admins.

When you have done that, you can add a link from a client to the loans:

Add a function 'configureSideMenu' to your clientadmin:

/**
 * {@inheritdoc}
 */
protected function configureSideMenu(MenuItemInterface $menu, $action, AdminInterface $childAdmin = null)
{
    // show link only on edit and show
    if (!$childAdmin && !in_array($action, array('edit', 'show'))) {
        return;
    }
    $admin = $this->isChild() ? $this->getParent() : $this;
    $id = $admin->getRequest()->get('id');


    $menu->addChild(
        'Loans',
        array('uri' => $this->getChild('your.loan.service.id')->generateUrl('list', array('id' => $id)))
    );
}

You can see a demo of this in the demo of sonata: http://demo.sonata-project.org/

click on 'Ecommerce' -> 'Order' -> 'specific order' -> 'Elements'

Here you can find the code of above example: https://github.com/sonata-project/ecommerce/tree/master/src/OrderBundle/Admin

More information on child-parent admin setup: Sonata/symfony - parent/child structure setup

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

configureRoutes() in admin class is not compatible with Sonata\AdminBundle\Admin\Admin::configureRoutes()

From Dev

configureRoutes() in admin class is not compatible with Sonata\AdminBundle\Admin\Admin::configureRoutes()

From Dev

sonata admin bundle symfony

From Dev

CKEditor not showing with Sonata Formatter (Sonata Admin Bundle)

From Dev

Use tags in Sonata Admin Bundle

From Dev

Configure Menu in Sonata Admin Bundle

From Dev

Conflicts with sonata admin bundle and LiipFunctionalTestBundle

From Dev

Sonata Admin Bundle - String Validation

From Dev

List Images in sonata admin bundle

From Dev

Use tags in Sonata Admin Bundle

From Dev

Conflicts with sonata admin bundle and LiipFunctionalTestBundle

From Dev

Sonata Media Bundle with Sonata Admin Bundle 3.0 (or 2.4)

From Dev

Sonata admin bundle : unable to remove relation with sonata_type_admin

From Dev

Sonata User Bundle + Admin Bundle admin redirect after login

From Dev

JSON array to table Sonata admin bundle

From Dev

Show sidebar in show view - Sonata admin bundle

From Dev

Error in file upload with sonata-admin bundle

From Dev

Sonata Admin Bundle custom routes using annotations

From Dev

Remove delete checkbox Sonata Admin Bundle

From Dev

Customise exported CSV content of Sonata Admin bundle

From Dev

Store Logged in user data in sonata admin bundle

From Dev

Is it possible to add a translatable association in Sonata Admin Bundle?

From Dev

Adding entity not managed by Sonata Admin Bundle

From Dev

disable action in sonata admin bundle CRUD

From Dev

Show sidebar in show view - Sonata admin bundle

From Dev

Sonata Admin Bundle custom routes using annotations

From Dev

Create new field type in sonata admin bundle

From Dev

How to display a photo in Sonata Admin Bundle

From Dev

Set a field like choose in sonata Admin bundle

Related Related

  1. 1

    configureRoutes() in admin class is not compatible with Sonata\AdminBundle\Admin\Admin::configureRoutes()

  2. 2

    configureRoutes() in admin class is not compatible with Sonata\AdminBundle\Admin\Admin::configureRoutes()

  3. 3

    sonata admin bundle symfony

  4. 4

    CKEditor not showing with Sonata Formatter (Sonata Admin Bundle)

  5. 5

    Use tags in Sonata Admin Bundle

  6. 6

    Configure Menu in Sonata Admin Bundle

  7. 7

    Conflicts with sonata admin bundle and LiipFunctionalTestBundle

  8. 8

    Sonata Admin Bundle - String Validation

  9. 9

    List Images in sonata admin bundle

  10. 10

    Use tags in Sonata Admin Bundle

  11. 11

    Conflicts with sonata admin bundle and LiipFunctionalTestBundle

  12. 12

    Sonata Media Bundle with Sonata Admin Bundle 3.0 (or 2.4)

  13. 13

    Sonata admin bundle : unable to remove relation with sonata_type_admin

  14. 14

    Sonata User Bundle + Admin Bundle admin redirect after login

  15. 15

    JSON array to table Sonata admin bundle

  16. 16

    Show sidebar in show view - Sonata admin bundle

  17. 17

    Error in file upload with sonata-admin bundle

  18. 18

    Sonata Admin Bundle custom routes using annotations

  19. 19

    Remove delete checkbox Sonata Admin Bundle

  20. 20

    Customise exported CSV content of Sonata Admin bundle

  21. 21

    Store Logged in user data in sonata admin bundle

  22. 22

    Is it possible to add a translatable association in Sonata Admin Bundle?

  23. 23

    Adding entity not managed by Sonata Admin Bundle

  24. 24

    disable action in sonata admin bundle CRUD

  25. 25

    Show sidebar in show view - Sonata admin bundle

  26. 26

    Sonata Admin Bundle custom routes using annotations

  27. 27

    Create new field type in sonata admin bundle

  28. 28

    How to display a photo in Sonata Admin Bundle

  29. 29

    Set a field like choose in sonata Admin bundle

HotTag

Archive