Sonata Admin Bundle configureRoutes getPersistentParameters

Sonata Admin Bundle configureRoutes getPersistentParameters

我对奏鸣曲还很陌生。我有一个涉及客户和贷款的项目。在 ClientsAdmin.php 中,我配置了 configureRoutes 和 getPersistentParameters 函数

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'),
    );
} 

此外,我已经覆盖了 CRUDController(和 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'),
        ));


    }
}

prestamos_clientes.html.twig 视图显示客户和贷款信息。

问题: 我想使用 $id 参数过滤我创建的列表视图 (transaccionesAction) 并查看特定客户的贷款。

谢谢。

您可以将管理员设置为另一个的 child。这样做的好处是,例如,您可以从一个特定客户单击以查看该特定客户的贷款列表..

为此,请遵循关于将管理员设置为 child-admin 主题的简约文档:https://sonata-project.org/bundles/admin/master/doc/reference/architecture.html#create-child-admins

完成后,您可以将来自客户的 link 添加到贷款中:

向您的客户端管理员添加功能 'configureSideMenu':

/**
 * {@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)))
    );
}

你可以在奏鸣曲的demo中看到这个demo: http://demo.sonata-project.org/

点击 'Ecommerce' -> 'Order' -> 'specific order' -> 'Elements'

在这里你可以找到上面例子的代码: https://github.com/sonata-project/ecommerce/tree/master/src/OrderBundle/Admin

有关 child-parent 管理员设置的更多信息: Sonata/symfony - parent/child structure setup