Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/242.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
Php 如何在使用DoctrineORMModule\Form\Element\EntitySelect注释时对实体(多工单关联)排序_Php_Doctrine_Zend Framework2 - Fatal编程技术网

Php 如何在使用DoctrineORMModule\Form\Element\EntitySelect注释时对实体(多工单关联)排序

Php 如何在使用DoctrineORMModule\Form\Element\EntitySelect注释时对实体(多工单关联)排序,php,doctrine,zend-framework2,Php,Doctrine,Zend Framework2,使用zf2和原则,我正在为我的Saleser类生成一个表单。 销售人员对商店有多个引用(即,一个商店可以有一个或多个销售人员) 由于我使用了@Annotation\Type(“DoctrineORMModule\Form\Element\EntitySelect”),因此表单中显示了一个下拉列表,这正是我想要的 我想要实现的是,在@manytone关联的框架中,根据商店的name属性对商店进行排序 以下是我拥有的HTML(生成的)代码: <select> <option

使用zf2和原则,我正在为我的Saleser类生成一个表单。 销售人员对商店有多个引用(即,一个商店可以有一个或多个销售人员)

由于我使用了@Annotation\Type(“DoctrineORMModule\Form\Element\EntitySelect”),因此表单中显示了一个下拉列表,这正是我想要的

我想要实现的是,在@manytone关联的框架中,根据商店的name属性对商店进行排序

以下是我拥有的HTML(生成的)代码:

<select>
    <option value="1" selected="selected">Store A</option>
    <option value="2">Store C</option> <- not ordered! probably because using row id for sorting.
    <option value="3">Store B</option>
<select>

感谢您的帮助。

添加到属性上方的实体

@ORM\OrderBy({“name”=“ASC”})

编辑

当然,名称和ASC需要替换为您喜欢/需要的值

多亏了,我可以想出如何在生成表单之后和绑定表单之前更改我的实体选择的选项

我是这样做的:

    $storeOptions = $this->form->get('store')->getOptions();

    /* mannually changing options.
       If someone knows how to achieve this using annotations, I am interested :-) */
    $storeOptions['is_method']   = true;
    $storeOptions['find_method'] = array(
        'name'   => 'findBy',
        'params' => array(
                'criteria' => array(), // no criteria since I want the whole list
                'orderBy'  => array('name' => 'ASC'),
        ),
    );

    $this->form->get('store')->setOptions($storeOptions);
现在我的实体选择器下拉列表按字母顺序排列。非常感谢,山姆

这对我有用

 * @Annotation\Options({"label":"Team(s):", "find_method"={"name": "findBy", "params"={"criteria"={}, "orderBy"={"name":"ASC"}}}})*

将尝试,但文档声明“除了任何@OneToMany或@ManyToMany注释外,您还可以通过以下方式指定@OrderBy”。没有提到很多事,这是我的情况。。。你尝试成功了吗?看:)谢谢,山姆。嗯。。。我使用$builder=new AnnotationBuilder()创建表单$此->表单=$builder->createForm('Customer\Entity\sales');因此,我将尝试找出表单中生成的“doctriemodule\Form\Element\ObjectSelect”,并以编程方式对其进行更改。但这并不是最“干净”的方式(当使用基于注释的表单创建方法时),我自己也不使用注释,所以我不能帮助解决这个问题,但这是目前唯一的方式。如果我没有弄错的话,我们在ZF2中没有
@Inject
。感谢您的评论:所以我调试并找到了EntitySelect元素,可以更改选项使其工作!谢谢你的提示(我在回答中相信了你),这种关系是一种多人的联系吗?
...
$form->prepare();
echo $this->form()->openTag($form);    
echo $this->formCollection($form);
echo $this->form()->closeTag();
...
    $storeOptions = $this->form->get('store')->getOptions();

    /* mannually changing options.
       If someone knows how to achieve this using annotations, I am interested :-) */
    $storeOptions['is_method']   = true;
    $storeOptions['find_method'] = array(
        'name'   => 'findBy',
        'params' => array(
                'criteria' => array(), // no criteria since I want the whole list
                'orderBy'  => array('name' => 'ASC'),
        ),
    );

    $this->form->get('store')->setOptions($storeOptions);
 * @Annotation\Options({"label":"Team(s):", "find_method"={"name": "findBy", "params"={"criteria"={}, "orderBy"={"name":"ASC"}}}})*