Unable to find template

384 views
Skip to first unread message

Massimiliano

unread,
Jun 30, 2016, 9:42:42 AM6/30/16
to symfony-it
Ciao,

sto prendendo questo errore ma ormai mi si appannano gli occhi non riesco più a leggere niente, è da ieri che ci sto su:

Unable to find template "AppBundle:Product:index.html.twig" (looked into: C:\Apache24\htdocs\MultipleUploadTest\app/Resources/views, C:\Apache24\htdocs\MultipleUploadTest\vendor\symfony\symfony\src\Symfony\Bridge\Twig/Resources/views/Form).


ho il controller ProductController:


<?php

namespace AppBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;

use AppBundle\Entity\Product;
use AppBundle\Entity\ProductPhoto;
use AppBundle\Form\ProductType;

/**
* Product controller.
*
*/

class ProductController extends Controller
{
private $ProductPhoto;

public function __construct()
{
$this
->ProductPhoto = new \AppBundle\Entity\ProductPhoto();
$this
->ProductPhoto->setNoFile(10);
}

/**
* Lists all Product entities.
*
*/

public function indexAction()
{
$em
= $this->getDoctrine()->getEntityManager();

$entities
= $em->getRepository('AppBundle:Product')->findAll();

return $this->render('AppBundle:Product:index.html.twig', array(
'entities' => $entities
));
}

/**
* Finds and displays a Product entity.
*
*/

public function showAction($id)
{
$em
= $this->getDoctrine()->getEntityManager();

$entity
= $em->getRepository('AppBundle:Product')->find($id);

if (!$entity) {
throw $this->createNotFoundException('Unable to find Product entity.');
}

$deleteForm
= $this->createDeleteForm($id);

return $this->render('AppBundle:Product:show.html.twig', array(
'entity'      => $entity,
'delete_form' => $deleteForm->createView(),

));
}

/**
* Displays a form to create a new Product entity.
*
*/

public function newAction()
{

$entity
= new Product();
$form  
= $this->createForm(new ProductType($this->ProductPhoto->getNoFile()), $entity);

return $this->render('AppBundle:Product:new.html.twig', array(
'entity' => $entity,
'form'   => $form->createView()
));
}

/**
* Creates a new Product entity.
*
*/

public function createAction()
{
$entity  
= new Product();

$request
= $this->getRequest();
$form    
= $this->createForm(new ProductType($this->ProductPhoto->getNoFile()), $entity);
$form
->bindRequest($request);

if ($form->isValid()) {

$em
= $this->getDoctrine()->getEntityManager();
$em
->persist($entity);
$em
->flush();

$files
=$request->files->get('appbundle_producttype');

foreach($files['ProductPhoto'] as $k => $file){

$someNewFilename
= date('Y-m-d-H-i-s').$file->getClientOriginalName();
$dir
=  __DIR__ . '/../../../../web/';

$form
['ProductPhoto'][$k]->getData()->move($dir.'/upload/', $someNewFilename);

$entityPhoto  
= new ProductPhoto();
$em
= $this->getDoctrine()->getEntityManager();
$entityPhoto
->setProduct($entity);
$entityPhoto
->setPath($someNewFilename);
$em
->persist($entityPhoto);
$em
->flush();
}

return $this->redirect($this->generateUrl('product_show', array('id' => $entity->getId())));

}

return $this->render('AppBundle:Product:new.html.twig', array(
'entity' => $entity,
'form'   => $form->createView()
));
}

/**
* Displays a form to edit an existing Product entity.
*
*/

public function editAction($id)
{
$em
= $this->getDoctrine()->getEntityManager();

$entity
= $em->getRepository('AppBundle:Product')->find($id);

if (!$entity) {
throw $this->createNotFoundException('Unable to find Product entity.');
}

$editForm
= $this->createForm(new ProductType(), $entity);
$deleteForm
= $this->createDeleteForm($id);

return $this->render('AppBundle:Product:edit.html.twig', array(
'entity'      => $entity,
'edit_form'   => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
));
}

/**
* Edits an existing Product entity.
*
*/

public function updateAction($id)
{
$em
= $this->getDoctrine()->getEntityManager();

$entity
= $em->getRepository('AppBundle:Product')->find($id);

if (!$entity) {
throw $this->createNotFoundException('Unable to find Product entity.');
}

$editForm  
= $this->createForm(new ProductType(), $entity);
$deleteForm
= $this->createDeleteForm($id);

$request
= $this->getRequest();

$editForm
->bindRequest($request);

if ($editForm->isValid()) {
$em
->persist($entity);
$em
->flush();

return $this->redirect($this->generateUrl('product_edit', array('id' => $id)));
}

return $this->render('AppBundle:Product:edit.html.twig', array(
'entity'      => $entity,
'edit_form'   => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
));
}

/**
* Deletes a Product entity.
*
*/

public function deleteAction($id)
{
$form
= $this->createDeleteForm($id);
$request
= $this->getRequest();

$form
->bindRequest($request);

if ($form->isValid()) {
$em
= $this->getDoctrine()->getEntityManager();
$entity
= $em->getRepository('AppBundle:Product')->find($id);

if (!$entity) {
throw $this->createNotFoundException('Unable to find Product entity.');
}

$em
->remove($entity);
$em
->flush();
}

return $this->redirect($this->generateUrl('product'));
}

private function createDeleteForm($id)
{
return $this->createFormBuilder(array('id' => $id))
->add('id', 'hidden')
->getForm()
;
}
}

e la struttura delle cartelle è questa:



grazie per l'aiuto

Massimiliano Arione

unread,
Jun 30, 2016, 9:50:56 AM6/30/16
to symfony-it
Come da documentazione:

$this->render('Product/index.html.twig')

ciao
M.
Reply all
Reply to author
Forward
0 new messages