小编xeo*_*eon的帖子

将数据从控制器传递到类型symfony2

如果我在我的表单中显示"实体"类型的字段,并且我想根据从控制器传递的参数过滤此实体类型,我该怎么做...?

//PlumeOptionsType.php
public function buildForm(FormBuilder $builder, array $options)
{
    $builder->add('framePlume', 'entity', array(
        'class' => 'DessinPlumeBundle:PhysicalPlume',
        'query_builder' => function(EntityRepository $er) {
                                return $er->createQueryBuilder('pp')
                                    ->where("pp.profile = :profile")
                                    ->orderBy('pp.index', 'ASC')
                                    ->setParameter('profile', ????)
                                ;
                            },

    ));
}

public function getName()
{
    return 'plumeOptions';
}

public function getDefaultOptions(array $options)
{
    return array(
            'data_class'      => 'Dessin\PlumeBundle\Entity\PlumeOptions',
            'csrf_protection' => true,
            'csrf_field_name' => '_token',
            // a unique key to help generate the secret token
            'intention'       => 'plumeOptions_item',
    );
}
}
Run Code Online (Sandbox Code Playgroud)

在控制器内部,我创建表单:

i have that argument that i need …
Run Code Online (Sandbox Code Playgroud)

symfony

25
推荐指数
1
解决办法
3万
查看次数

读取对象持久化但尚未用doctrine刷新

我是symfony2和doctrine的新手.这是看到的问题.我不能用:

$repository = $this->getDoctrine()->getRepository('entity');
$my_object = $repository->findOneBy($index);
Run Code Online (Sandbox Code Playgroud)

在一个持久的物体上,但不要冲洗!我认为getRepository从DB读取,因此它不会找到未刷新的对象.

我的问题:在我冲洗整个批次之前,如何阅读那些持久存在的对象(我认为它们是在"学说会话"中的某个地方)重新使用它们?

每个配置文件都有256个物理羽流.

每个配置文件都plumeOptions分配了1条记录.

plumeOptions,我有一个盒式弹药,它是一个FK PhysicalPlume.

每个羽流都由ID(自动生成)和INDEX(用户生成的)标识.

规则:我说配置文件1的physical_plume_index数字3(=索引)连接到它.

现在,我想将包含所有相关数据的配置文件复制到另一个配置文件.

新的个人资料已创建.从旧配置文件创建并复制新的256个羽流.

我想将新的配置文件链接到新的羽流指数3.

点击这里:http://pastebin.com/WFa8vkt1

symfony doctrine-orm

19
推荐指数
1
解决办法
2万
查看次数

使用thymeleaf + spring创建自定义标签(就像JSP一样)

我正在尝试使用Thymeleaf创建自定义标记,就像在JSP中一样.我现在的标签是:

<select th:include="fragments/combobox :: combobox_beans (beans=${@accountService.getAccounts()}, innerHTML='id,description,currency', separator=' - ', dumbHtmlName='List of accounts', name='sender' )" th:remove="tag"></select>
Run Code Online (Sandbox Code Playgroud)

目的只是定义bean列表,要在屏幕上显示的bean的属性,它们之间的分隔符,显示为本机模板时的默认值,以及我们在此处理的原始bean的属性名称.

combobox.html:

<div th:fragment="combobox_beans (beans, innerHTML, separator, dumbHtmlName, name)">
<select th:field="*{__${name}__}" class="combobox form-control" required="required">
    <option th:each="obj : ${beans}" th:with="valueAsString=${#strings.replace( 'obj.' + innerHTML, ',', '+''  __${separator}__ ''+ obj.')}"
        th:value="${obj}" th:text="${valueAsString}" >            
        <p th:text="${dumbHtmlName}" th:remove="tag"></p>
    </option>
</select>
Run Code Online (Sandbox Code Playgroud)

我需要选项标签的文本基于片段的innerHTML属性(innerHTML ='id,description,devise')中设置的属性.我最终选择了这个文字:

<option value="...">obj.id+' - '+ obj.description+' - '+ obj.currency</option>
Run Code Online (Sandbox Code Playgroud)

而不是期望的结果

<option value="...">2 - primary - USD</option>
Run Code Online (Sandbox Code Playgroud)

我知道这是由于使用了Strings库导致字符串.有没有办法让Thymeleaf重新评估这个字符串再被理解为一个对象?

也许在这种情况下使用字符串库是错误的...也许我需要使用th:each将每个bean作为一个对象进行处理并读取它的属性,但是又如何只获取innerHtml中指定的属性?

任何人都有解决方案或解决方案吗?
谢谢.

spring-mvc thymeleaf

2
推荐指数
1
解决办法
3297
查看次数

标签 统计

symfony ×2

doctrine-orm ×1

spring-mvc ×1

thymeleaf ×1