Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Select Symfony2:Sonata管理:链式选择器,Sonata类型参考_Select_Symfony_Sonata Admin_Chainable - Fatal编程技术网

Select Symfony2:Sonata管理:链式选择器,Sonata类型参考

Select Symfony2:Sonata管理:链式选择器,Sonata类型参考,select,symfony,sonata-admin,chainable,Select,Symfony,Sonata Admin,Chainable,有人实施过奏鸣曲类型、模型、参考表格类型吗 我需要把州和国家的关系联系起来,我在幻灯片上读到,索纳塔的型号参考是可行的,但我找不到任何文档 如何实施?或者还有什么其他选项可以将两个或多个字段与数据库/模型数据关联/链接?今天之前,我使用自定义AJAX来实现这一点 客户: // Override of admin-bundle/Resources/Views/CRUD/base_edit.html.twig {% block javascripts %} {{ parent() }} &

有人实施过奏鸣曲类型、模型、参考表格类型吗

我需要把州和国家的关系联系起来,我在幻灯片上读到,索纳塔的型号参考是可行的,但我找不到任何文档


如何实施?或者还有什么其他选项可以将两个或多个字段与数据库/模型数据关联/链接?

今天之前,我使用自定义AJAX来实现这一点

客户:

// Override of admin-bundle/Resources/Views/CRUD/base_edit.html.twig

{% block javascripts %}
  {{ parent() }}
  <script type="text/javascript">
    $(document).ready(function() {
      $('#{{ admin.uniqId }}_parent').change(function() {
        var parent = $(this);
        var child = $('#{{ admin.uniqId }}_child');
        $.get('/admin/child/get_choices/' + parent.val(), function(data) {
          child.empty().append(data);
        }, 'text')
        .then(function() {
          var childFirstOption = child.find('option:first');
          var childDisplayText = $("#field_widget_{{ admin.uniqId }}_child .select2-chosen");
          childFirstOption.attr("selected", true);
          childDisplayText.text(childFirstOption.text());
        });
      });
    });
  </script>
{% endblock %}

我将很快尝试实施sonata_type_model_reference,然后回来编辑。

您所说的“链”两种关系是什么意思?是否要更新与相关字段值对应的字段的选项?示例:我们有一个包含类别的列表框,第二个包含子类别的列表框,以及一个从第一个到第二个的oneToMany。在选择一个类别时,我们只使用category=selected的条目更新subcategories列表框的可用选项。这是你想要的吗?@chalasr是的,那是我想要的,但那是很久以前的事了,我们确实停止了那个项目。但是,如果你有一个解决方案,请随时提供你的答案!
// src/App/AdminBundle/Controller/ChildAdminController.php

class ChildAdminController extends Controller
{
    //...

    public function getChoicesAction($parent)
    {
        $html = "";
        $parent = $this->getDoctrine()
            ->getRepository('AppAdminBundle:Parent')
            ->find($parent)
        ;
        $choices = $parent->getChilds();

        foreach($choices as $choice) {
            $html .= '<option value="' . $choice->getId() . '" >' . $choice->getLabel() . '</option>';
        }

        return new Response($html);
    }

    //...
}
// src/App/AdminBundle/Admin/ChildAdmin.php

//...
use Sonata\AdminBundle\Route\RouteCollection;

class ChildAdmin extends Admin
{
    //...

    protected function configureRoutes(RouteCollection $collection)
    {
        $collection->add('get_choices', 'get_choices/{parent}', array(), array(), array('expose' => true));
    }

    // ...
}