2015-05-05 51 views
0

我在索纳塔很新。我有一个涉及客户和贷款的项目。在ClientsAdmin.php我已配置configureRoutes和getPersistentParameters功能索纳塔管理套件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)并查看特定客户端的贷款。

谢谢。

+0

为什么不创建贷款实体和'configuredatagridfilter管理员()'添加客户端列表 –

回答

1

您可以将管理员设置为另一个管理员的孩子。这有一个好处,例如,您可以从一个特定的客户端点击到该特定客户端的贷款清单。

要做到这一点,请按照关于将管理员设置为子管理员的简单文档:https://sonata-project.org/bundles/admin/master/doc/reference/architecture.html#create-child-admins

当你这样做,你可以从客户端链接添加到贷款:

添加功能“configureSideMenu”你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))) 
    ); 
} 

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

点击 '电子商务' - > '订购' - > '特定的顺序' - > '元素'

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

上亲子管理设置

的更多信息: Sonata/symfony - parent/child structure setup

+0

谢谢@ 11mb!非常有帮助。在客户的编辑视图中,我有一个链接到贷款清单,甚至可以从那里编辑它们。卓越的工作! 即使我将一个Loans按钮添加到_action元素并且像快捷方式一样工作。 为了继续使用这种方法,我已经将贷款连接到集合。工作得很好。 但是,当我去编辑一个特定的客户端,点击贷款和编辑其中之一,我不能添加菜单集合继续与unchained关系? 另一种方式来做到这一点将直接编辑贷款的链接(不嵌入客户端编辑视图) –

+0

好它为你工作..索纳塔是非常善于隐藏所有有趣的东西;)..我不认为我真的很了解你在评论中的问题..也许你可以改述一下吗?我对我的答案有额外的评论:我注意到我的搜索功能不再工作了......我更改了$ admin-> getRequest()代码..请参阅此处获取更多信息:http://stackoverflow.com/questions/19551715 /奏鸣曲管理搜索功能 – 11mb

+0

对不起,我的英语。我会尽力解释我的问题。 例如,在贷款类中,我有一个指向客户端类的属性。而且,我还添加了一个指向卖家类的属性。 当我配置这样的LoansAdmin配置功能: $ this-> parentAssociationMapping ='seller'; $ this-> parentAssociationMapping ='client'; 因此,当我在客户端列表中,贷款按钮带我到按客户端属性过滤的贷款列表(在configureDatagridFilters中) 但是,当我去卖家列表时,贷款按钮不起作用,并且卖家ID不工作!**。 **我可以这样做吗?** –