I need to instance different object into a same method. I have found soluce here:
Creating PHP class instance with a string
But when I use that on Controller of Symfony2 I have this error :
Attempted to load class "PhotoType" from the global namespace. Did you forget a "use" statement?
I didn't understand because I have add all of my "use"
namespace DIVE\FileUploaderBundle\Controller;
use DIVE\FileUploaderBundle\Entity\Photo;
use DIVE\FileUploaderBundle\Form\PhotoType;
...
class DefaultController extends Controller {
public function listFileAction($fileType) {
$em = $this->getDoctrine()->getManager();
$repository = $em->getRepository("FDMFileUploaderBundle:".$fileType);
$files = $repository->findAll();
$forms = array();
foreach ($files as $file) {
$class = $fileType."Type";
array_push($forms, $this->get('form.factory')->create(new $class(), $file));
}
$formViews = array();
foreach ($forms as $form) {
array_push($formViews, $form->createView());
}
return $this->render("FDMFileUploaderBundle:Default:list".$fileType.".html.twig", array(
"forms" => $formViews
)
);
}
}
Sorry for my English, I am learning it.