2015-05-05 64 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不工作!**。 **我可以這樣做嗎?** –