2014-12-21 11 views
1

我已經爲CRUD重寫了Sensio Generator Bundle,以便更好地滿足我的需求。如何在Sensio Generator Bundle中循環顯示錶單域

我想要做的是能夠遍歷實體字段。 默認在show.html.twig中完成,但不在新的和編輯視圖中完成。

當我在new.html.twig.twig中實現相同的邏輯時,雖然它對edit.html.twig.twig有效,但它不起作用。

{#app/Resources/SensioGeneratorBundle/skeleton/crud/views/new.html.twig.twig#} 

{% for field, metadata in fields %} 
    {% if field not in 'id' %} 
     {{ '{{ form_row(edit_form.' ~ field ~ ')}}' }} 
    {% endif %} 
{% endfor %} 

當運行發電機,所述錯誤是:變量「字段」不「污物/視圖/ new.html.twig.twig」第9行

+0

「新」視圖生成器(https://github.com/sensiolabs/SensioGeneratorBundle/blob/master/Generator/DoctrineCrudGenerator.php#L242-L256)不會將字段傳遞給模板呈現。我假設你需要編寫'renderFile'方法來包含''fields'=> $ this-> metadata-> fieldMappings',但顯然這需要擴展實際的類。 – qooplmao

+0

而你已經完成了這項工作。便便。 – qooplmao

+0

是的。謝謝您的回答。編寫問題有時有助於找到正確的方向。 – curuba

回答

1

確定存在,實際上它是Sensio Generator Bundle中的一個問題。 在文件中:sensio \ generator-bundle \ Sensio \ Bundle \ GeneratorBundle \ Generator \ DoctrineCrudGenerator.php generateNewView函數缺少參數。它不會傳遞字段而不是generateShowView。

下面是比較:

protected function generateNewView($dir) 
{ 
    $this->renderFile('crud/views/new.html.twig.twig', $dir.'/new.html.twig', array(
     'bundle'   => $this->bundle->getName(), 
     'entity'   => $this->entity, 
     'route_prefix'  => $this->routePrefix, 
     'route_name_prefix' => $this->routeNamePrefix, 
     'actions'   => $this->actions, 
    )); 
} 

protected function generateShowView($dir) 
{ 
    $this->renderFile('crud/views/show.html.twig.twig', $dir.'/show.html.twig', array(
     'bundle'   => $this->bundle->getName(), 
     'entity'   => $this->entity, 
     'fields'   => $this->metadata->fieldMappings, 
     'actions'   => $this->actions, 
     'route_prefix'  => $this->routePrefix, 
     'route_name_prefix' => $this->routeNamePrefix, 
    )); 
} 

我會嘗試發佈此作爲改進。

+0

發表在這裏:[gitHub](https://github.com/sensiolabs/SensioGeneratorBundle/issues/325) – curuba

+0

問題已修復:https://github.com/sensiolabs/SensioGeneratorBundle/pull/401 – curuba