php - Hello Expected argument of type "string", "bundle\FrontBundle\Form\Type\PrestationType" given -
i test application , i'm error please
my formtype
namespace bundle\frontbundle\form\type; use doctrine\orm\entityrepository; use symfony\component\form\abstracttype; use symfony\component\form\formbuilderinterface; use symfony\component\optionsresolver\optionsresolver; class prestationtype extends abstracttype { public function buildform(formbuilderinterface $builder, array $options) { $builder ->add('path') ->add('alt') ->add('save', 'submit'); } public function configureoptions(optionsresolver $resolver) { $resolver->setdefaults(array( 'data_class' => 'bundle\frontbundle\entity\image', )); } public function getname() { return 'prestation'; } }
my entity
<?php namespace bundle\frontbundle\entity; use doctrine\orm\mapping orm; /** * image * * @orm\table(name="image") * @orm\entity(repositoryclass="bundle\frontbundle\repository\imagerepository") */ class image { /** * @var int * * @orm\column(name="id", type="integer") * @orm\id * @orm\generatedvalue(strategy="auto") */ protected $id; /** * @var string * * @orm\column(name="path", type="string", length=255) */ protected $path; /** * @var string * * @orm\column(name="alt", type="string", length=255) */ protected $alt; /** * id * * @return int */ public function getid() { return $this->id; } }
my controller
<?php namespace bundle\frontbundle\controller; use bundle\frontbundle\entity\image; use bundle\frontbundle\entity\prestation; use bundle\frontbundle\form\type\prestationtype; use symfony\bundle\frameworkbundle\controller\controller; use symfony\component\httpfoundation\request; class frontcontroller extends controller { public function indexaction(request $request) { $form = $this->createform(new prestationtype()); $form->handlerequest($request); return $this->render('frontbundle::index.html.twig', array('form' => $form->createview())); } public function listaction() { return $this->render('frontbundle:pages:list.html.twig'); } }
and output error
expected argument of type "string", "bundle\frontbundle\form\type\prestationtype" given
and stack trace
[1] symfony\component\form\exception\unexpectedtypeexception: expected argument of type "string", "bundle\frontbundle\form\type\prestationtype" given @ n/a in /users/sylva/garage/vendor/symfony/symfony/src/symfony/component/form/formfactory.php line 64
at symfony\component\form\formfactory->createbuilder(object(prestationtype),
null, array()) in /users/sylva/garage/vendor/symfony/symfony/src/symfony/component/form/formfactory.php line 39
at symfony\component\form\formfactory->create(object(prestationtype),
null, array()) in /users/sylva/garage/vendor/symfony/symfony/src/symfony/bundle/frameworkbundle/controller/controller.php line 285
at symfony\bundle\frameworkbundle\controller\controller->createform(object(prestationtype)) in /users/sylva/garage/src/bundle/frontbundle/controller/frontcontroller.php
line 19
at bundle\frontbundle\controller\frontcontroller->indexaction(object(request)) in line @ call_user_func_array(array(object(frontcontroller), 'indexaction'), array(object(request))) in /users/sylva/garage/vendor/symfony/symfony/src/symfony/component/httpkernel/httpkernel.php
line 139
at symfony\component\httpkernel\httpkernel->handleraw(object(request),
'1') in /users/sylva/garage/vendor/symfony/symfony/src/symfony/component/httpkernel/httpkernel.php line 62
at symfony\component\httpkernel\httpkernel->handle(object(request), '1',
true) in /users/sylva/garage/vendor/symfony/symfony/src/symfony/component/httpkernel/kernel.php line 169
at symfony\component\httpkernel\kernel->handle(object(request)) in /users/sylva/garage/web/app_dev.php line 30
thanx guy
$this->createform() expects first argument class name of form want instantiate.
replace:
$form = $this->createform(new prestationtype());
with
// php 5.5+ $form = $this->createform(prestationtype::class); // older versions $form = $this->createform('bundle\frontbundle\form\type\prestationtype');
Comments
Post a Comment