Php 如何在Symfony 2指令生成的CRUD中将editAction的逻辑放在showAction中?
我有一个Symfony 2项目,其中包含一些数据库实体的条令生成的CRUD(由'app/console条令:generate:CRUD'生成)。在我的具体案例中,我有像TariffMc、TariffMcServiceMcRelation这样的实体。一个TariffMc实体可以属于多个TariffMcServiceMcRelation 我有一个TariffMc的showAction,为这个动作代码生成了默认值。我想在下面列出所有TariffMcServiceMsRelation,它们属于这个TariffMc实体 我能够对TariffMc的showAction进行一些更改,因此该页面现在呈现TariffMc实体以及与该实体相关的所有TariffMcServiceMcRelation实体。我尝试了很多次,但没有得到我需要的最终结果:我需要为TariffMc呈现showAction的结果,下面必须有所有与此TariffMc TariffmcServicemRelation实体相关的内容,可以编辑和删除同一页面上的每个TariffmcServicemRelation实体 那么,我现在拥有的是: 粗略地说,作为最终结果,我需要的是: TariffMc“显示”模板:Php 如何在Symfony 2指令生成的CRUD中将editAction的逻辑放在showAction中?,php,entity-framework,symfony,doctrine-orm,doctrine,Php,Entity Framework,Symfony,Doctrine Orm,Doctrine,我有一个Symfony 2项目,其中包含一些数据库实体的条令生成的CRUD(由'app/console条令:generate:CRUD'生成)。在我的具体案例中,我有像TariffMc、TariffMcServiceMcRelation这样的实体。一个TariffMc实体可以属于多个TariffMcServiceMcRelation 我有一个TariffMc的showAction,为这个动作代码生成了默认值。我想在下面列出所有TariffMcServiceMsRelation,它们属于这个Tar
{% extends 'menu.html.twig' %}
{% block content %}
<h1>TariffMc</h1>
<table class="record_properties" border="1">
<tbody>
<tr>
<th>ID</th>
<td>{{ entity.id }}</td>
</tr>
<tr>
<th>Партнер</th>
<td>{{ entity.user }}</td>
</tr>
<tr>
<th>Хэш</th>
<td>{{ entity.hash }}</td>
</tr>
<tr>
<th>URL для уведомлений о статусах платежей</th>
<td>{{ entity.notificationUrl }}</td>
</tr>
</tbody>
</table>
<ul class="record_actions">
<li>
<a href="{{ path('system_settings_mc_tariffs') }}">
Back to list
</a>
</li>
<li>
<a href="{{ path('system_settings_mc_tariffs_edit', { 'id': entity.id }) }}">
Edit
</a>
</li>
<li>{{ form(delete_form) }}</li>
</ul>
{# Вывод в таблице всех записей из таблицы tariff_mc_service_mc_relation, которые относятся к данному тарифу #}
<h1>TariffMcServiceMcRelation</h1>
{% if relations %}
<table class="records_list" border="1">
<thead>
<tr>
<th>Оператор</th>
<th>ID сервиса</th>
<th>Стандартный успешный ответ на запрос КП</th>
<th>description</th>
<th>Комиссия</th>
<th>Фильтр</th>
</tr>
</thead>
<tbody>
{% for relation in relations %}
<tr>
<td>{{ relation.operator }}</td>
<td>{{ relation.id }}</td>
<td>{{ relation.successMessage }}</td>
<td>{{ relation.description }}</td>
<td>{{ relation.commission }}</td>
<td>{{ relation.filter }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
Нет отчислений для операторов
{% endif %}
<ul>
<li>
<a href="{{ path('system_settings_mc_tariff_mc_service_mc_relation_new') }}">
Create TariffMcServiceMcRelation
</a>
</li>
</ul>
{% endblock %}
<h1>TariffMcServiceMcRelation edit</h1>
{{ form(edit_form) }}
<ul class="record_actions">
<li>
<a href="{{ path('system_settings_mc_tariff_mc_service_mc_relation') }}">
Back to list
</a>
</li>
<li>{{ form(delete_form) }}</li>
public function showAction($id)
{
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('AppBundle:TariffMc')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find TariffMc entity.');
}
$deleteForm = $this->createDeleteForm($id);
return array(
'entity' => $entity,
'delete_form' => $deleteForm->createView(),
);
}
我需要以何种方式修改TariffMc的showAction()和TariffMc的show template,以便获得所需的结果?为什么要尝试制作混合显示/编辑页面?显示应该只显示数据,编辑应该只编辑数据 执行您正尝试执行的操作的功能已经存在: 在configureFormFields中:
$formBuilder
->add('foobarRelationName', 'sonata_type_collection', array(),
array(
'edit' => 'inline',
'inline' => 'table',
))
请注意,以这种方式编辑许多相关实体可能会对性能和内存使用产生重大影响
编辑:我发现索纳塔的文档很难使用,而且缺少信息。尝试使用sonata字段类型来处理关系时,反复尝试和大量stackoverflow搜索是您的朋友。但是我可以在不安装sonata捆绑包的情况下实现所需的功能吗?下面是我在项目中安装的捆绑包列表:@koroveo是的,您可以自己实现该功能。但是,实现您所讨论的功能是非常重要的,需要做出设计选择,远远超出stackoverflow回答的范围。谢谢。最后,我在这里找到了问题的一般解决方案: