1
當我想顯示包含列表的頁面時,我發現另一個演出,不像我的模板。編輯CRUD模板
我該怎麼辦?您可以在下面找到視圖的代碼和實體:
{% extends "MyAppProjetBundle::layout.html.twig" %}
{% block content %}
<table class="record_properties">
<tbody>
<tr>
<th>Id</th>
<td>{{ entity.id }}</td>
</tr>
<tr>
<th>Titre</th>
<td>{{ entity.titre }}</td>
</tr>
<tr>
<th>Type</th>
<td>{{ entity.type }}</td>
</tr>
<tr>
<th>Categorie</th>
<td>{{ entity.categorie }}</td>
</tr>
<tr>
<th>Ville</th>
<td>{{ entity.ville }}</td>
</tr>
<tr>
<th>Prix</th>
<td>{{ entity.prix }}</td>
</tr>
<tr>
<th>Surface</th>
<td>{{ entity.surface }}</td>
</tr>
<tr>
<th>Description</th>
<td>{{ entity.description }}</td>
</tr>
<tr>
<th>Validation</th>
<td>{{ entity.validation }}</td>
</tr>
<tr>
<th>Dateinsertion</th>
<td>{{ entity.dateInsertion|date('Y-m-d H:i:s') }}</td>
</tr>
<tr>
<th>Iduser</th>
<td>{{ entity.idUser }}</td>
</tr>
<tr>
<th>Idgerant</th>
<td>{{ entity.idGerant }}</td>
</tr>
</tbody>
</table>
<ul class="record_actions">
<li>
<a href="{{ path('offre') }}">
Back to the list
</a>
</li>
<li>
<a href="{{ path('offre_edit', { 'id': entity.id }) }}">
Edit
</a>
</li>
<li>{{ form(delete_form) }}</li>
</ul>
{% endblock %}
實體:
<?php
namespace MyApp\ProjetBundle\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use MyApp\ProjetBundle\Entity\Offre;
use MyApp\ProjetBundle\Form\OffreType;
/**
* Offre controller.
*
*/
class OffreController extends Controller
{
/**
* Lists all Offre entities.
*
*/
public function indexAction()
{
$em = $this->getDoctrine()->getManager();
$entities = $em->getRepository('MyAppProjetBundle:Offre')->findAll();
return $this->render('MyAppProjetBundle:Offre:index.html.twig', array(
'entities' => $entities,
));
}
/**
* Creates a new Offre entity.
*
*/
public function createAction(Request $request)
{
$entity = new Offre();
$form = $this->createCreateForm($entity);
$form->handleRequest($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($entity);
$em->flush();
return $this->redirect($this->generateUrl('offre_show', array('id' => $entity->getId())));
}
return $this->render('MyAppProjetBundle:Offre:new.html.twig', array(
'entity' => $entity,
'form' => $form->createView(),
));
}
/**
* Creates a form to create a Offre entity.
*
* @param Offre $entity The entity
*
* @return \Symfony\Component\Form\Form The form
*/
private function createCreateForm(Offre $entity)
{
$form = $this->createForm(new OffreType(), $entity, array(
'action' => $this->generateUrl('offre_create'),
'method' => 'POST',
));
$form->add('submit', 'submit', array('label' => 'Create'));
return $form;
}
/**
* Displays a form to create a new Offre entity.
*
*/
public function newAction()
{
$entity = new Offre();
$form = $this->createCreateForm($entity);
return $this->render('MyAppProjetBundle:Offre:new.html.twig', array(
'entity' => $entity,
'form' => $form->createView(),
));
}
/**
* Finds and displays a Offre entity.
*
*/
public function showAction($id)
{
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('MyAppProjetBundle:Offre')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Offre entity.');
}
$deleteForm = $this->createDeleteForm($id);
return $this->render('MyAppProjetBundle:Offre:show.html.twig', array(
'entity' => $entity,
'delete_form' => $deleteForm->createView(),
));
}
/**
* Displays a form to edit an existing Offre entity.
*
*/
public function editAction($id)
{
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('MyAppProjetBundle:Offre')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Offre entity.');
}
$editForm = $this->createEditForm($entity);
$deleteForm = $this->createDeleteForm($id);
return $this->render('MyAppProjetBundle:Offre:edit.html.twig', array(
'entity' => $entity,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
));
}
/**
* Creates a form to edit a Offre entity.
*
* @param Offre $entity The entity
*
* @return \Symfony\Component\Form\Form The form
*/
private function createEditForm(Offre $entity)
{
$form = $this->createForm(new OffreType(), $entity, array(
'action' => $this->generateUrl('offre_update', array('id' => $entity->getId())),
'method' => 'PUT',
));
$form->add('submit', 'submit', array('label' => 'Update'));
return $form;
}
/**
* Edits an existing Offre entity.
*
*/
public function updateAction(Request $request, $id)
{
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('MyAppProjetBundle:Offre')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Offre entity.');
}
$deleteForm = $this->createDeleteForm($id);
$editForm = $this->createEditForm($entity);
$editForm->handleRequest($request);
if ($editForm->isValid()) {
$em->flush();
return $this->redirect($this->generateUrl('offre_edit', array('id' => $id)));
}
return $this->render('MyAppProjetBundle:Offre:edit.html.twig', array(
'entity' => $entity,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
));
}
/**
* Deletes a Offre entity.
*
*/
public function deleteAction(Request $request, $id)
{
$form = $this->createDeleteForm($id);
$form->handleRequest($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('MyAppProjetBundle:Offre')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Offre entity.');
}
$em->remove($entity);
$em->flush();
}
return $this->redirect($this->generateUrl('offre'));
}
/**
* Creates a form to delete a Offre entity by id.
*
* @param mixed $id The entity id
*
* @return \Symfony\Component\Form\Form The form
*/
private function createDeleteForm($id)
{
return $this->createFormBuilder()
->setAction($this->generateUrl('offre_delete', array('id' => $id)))
->setMethod('DELETE')
->add('submit', 'submit', array('label' => 'Delete'))
->getForm()
;
}
}
結果:http://i.stack.imgur.com/xbqt9.jpg
您是否在樹枝中啓用了緩存?如果是這樣,一定要設置自動重裝爲真 – DarkBee 2014-12-04 12:36:53
不,我沒有任何問題與緩存 – Salma 2014-12-04 13:15:51