2014-02-28 43 views
1

我有一些令人頭痛的問題,我想重新制作輪子。索納塔管理軟件包:從嵌入式管理員類訪問子編輯路線

在奏鳴曲管理包中,我試圖通過所有管理實體進行邏輯導航。

每個實體都在這樣的級聯相關:programEntity - > LevelEntity - > ExerciceEntity - > somethingEntity - >等

從我讀過,奏鳴曲管理員束手柄(希望這會改變),只有一個嵌入父級和子級管理員級別之間的關係。

事實是不是很方便,能夠編輯/列表父母的孩子,回到儀表盤編輯/列表父母的孫子

我目前正在試圖使自定義路線編輯parend的孩子從編輯路線刪除父路徑:

http://localhost/domain/admin/acme/app/parent/4/child/3/edit 

我想通過直接一個這樣的替換此網址:

http://localhost/domain/admin/acme/app/child/3/edit 

這樣我就可以從父母選擇的孩子那裏接觸到大孩子。

我試圖從sonata adminClass中覆蓋generateObjectUrl和generateUrl而沒有成功,我也在爲每個實體重寫模板,但它不是很適合poo。

有什麼想法?

回答

1

我能找到一種方法來解決此問題:在你自己的包

1)覆蓋base_list_field(將文件複製在供應商\奏鳴曲項目\ ADMIN束\索納塔\ AdminBundle \資源\意見\ CRUD \ base_list_field.html.twig在自己的包一樣極致/包/資源/視圖/ CRUD)

2)修改這樣的文件長相:

{# 

This file is part of the Sonata package. 

(c) Thomas Rabaix <[email protected]> 

For the full copyright and license information, please view the LICENSE 
file that was distributed with this source code. 

#} 

<td class="sonata-ba-list-field sonata-ba-list-field-{{ field_description.type }}"  objectId="{{ admin.id(object) }}"> 
    {% if 
     field_description.options.identifier is defined 
    and field_description.options.route is defined 
    and admin.isGranted(field_description.options.route.name == 'show' ? 'VIEW' : field_description.options.route.name|upper, object) 
    and admin.hasRoute(field_description.options.route.name) 
%} 

<script type="text/javascript"> 
    var route = "{{ admin.generateObjectUrl(field_description.options.route.name, object, field_description.options.route.parameters) }}"; 
    var url = route.split(/(app)\//); 
    var tabUrl = url[2].split ("/"); 
    alert ('test') ; 

    var new_url = ''; 

    // case where adminclass is a child 
    if (tabUrl.length == 5) 
    { 
     new_url = url[0] + url[1] + '/' + tabUrl[2] + '/' + tabUrl[3] + '/' + tabUrl[4] ; 
    } 

    // case where adminclass is not a child 
    if (tabUrl.length == 3) 
    { 
     new_url = "{{ admin.generateObjectUrl(field_description.options.route.name, object, field_description.options.route.parameters) }}"; 
    } 

    document.write({%raw%}"<a href='"{%endraw%} + new_url + {%raw%}"'>{%endraw%}{%- block field %}{{ value }}{% endblock -%}{%raw%}</a>"{%endraw%}); 
</script> 
{% else %} 
    {{ block('field') }} 
{% endif %} 

如果tabUrl(與'/'分開的URL)找到5個結果,這意味着我們在嵌入的管理類中,否則它是一個正常的管理類列表。

代碼不是很乾淨和優化,但它的工作原理。

3)更新config.yml

sonata_admin: 
title: Bonk 
title_logo: public/img/logo-admin.png 
security: 
    handler: sonata.admin.security.handler.noop 
templates: 
    # default global templates 
    layout: SonataAdminBundle::standard_layout.html.twig 
    ajax: SonataAdminBundle::ajax_layout.html.twig 
    dashboard: SonataAdminBundle:Core:dashboard.html.twig 

    # default actions templates, should extend a global templates 
    list: SonataAdminBundle:CRUD:list.html.twig 
    show: SonataAdminBundle:CRUD:show.html.twig 
    edit: SonataAdminBundle:CRUD:edit.html.twig 

    ------>>> base_list_field: AcmeMyBundle:CRUD:base_list_field.html.twig 

sonata_doctrine_orm_admin: 
# default value is null, so doctrine uses the value defined in the configuration 
entity_manager: '@doctrine.orm.entity_manager' 

templates: 
    form: 
     - SonataDoctrineORMAdminBundle:Form:form_admin_fields.html.twig 
    filter: 
    - SonataDoctrineORMAdminBundle:Form:filter_admin_fields.html.twig 
    types: 
     list: 
      array:  SonataAdminBundle:CRUD:list_array.html.twig 
      boolean: SonataAdminBundle:CRUD:list_boolean.html.twig 
      date:  SonataAdminBundle:CRUD:list_date.html.twig 
      time:  SonataAdminBundle:CRUD:list_time.html.twig 
      datetime: SonataAdminBundle:CRUD:list_datetime.html.twig 
      text:  acmeMyBundle:CRUD:base_list_field.html.twig 
      trans:  SonataAdminBundle:CRUD:list_trans.html.twig 
      string:  acmeMyBundle:CRUD:base_list_field.html.twig 
      smallint: acmeMyBundle:CRUD:base_list_field.html.twig 
      bigint:  acmeMyBundle:CRUD:base_list_field.html.twig 
      integer: acmeMyBundle:CRUD:base_list_field.html.twig 
      decimal: acmeMyBundle:CRUD:base_list_field.html.twig 
      identifier: acmeMyBundle:CRUD:base_list_field.html.twig 

希望這將幫助!