点击按钮的一条路线适用于此控制器:
public function addAction(Request $request){
$em = $this->getDoctrine()->getManager();
$spotEntity = $this->getCurrentSpot();
$permitsidrand = rand(0, 1000000000000);
$currentDate = new DateTime();
$permitsrepo = new Permits();
$permitsrepo->setCreatedat($currentDate);
$permitsrepo->setPermitid($permitsidrand);
$permitsrepo->setPermitsSpot($spotEntity);
$em->persist($permitsrepo);
$em->flush();
return $this->redirect($this->generateUrl('permits_add', array('id' => $permitsrepo->getId())));
}
所以我想创建新的Object并用几个变量填充它,之后我想重定向到屏幕,表单将更新我刚刚添加的数据库中的记录。
这是第二个功能(这是我点击按钮后重定向到的那个)
public function addfullAction(Request $request, $id){
$permitsidrand = rand(0, 1000000000000);
$currentDate = new DateTime();
$permitsrepo = $this->getDoctrine()->getRepository('MainCoreBundle:Permits');
$perm= $permitsrepo->find($id);
$form = $this->createForm(new PermitsType(), $permitsrepo);
$permitsrepo->setCreatedat($currentDate);
$permitsrepo->setPermitid($permitsidrand);
$permitsrepo->setPermitsSpot($spotEntity);
if ($request->isMethod('POST')) {
$form->bind($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($permitsrepo);
$em->flush();
return $this->redirect($this->generateUrl('permits_show'));
}
}
return $this->render('MainAdminBundle:Permits:add.html.twig', $this->getViewConstants(array(
'form' => $form->createView(),
'rand' =>$permitsidrand
)));
}
当我点击那个我提到的按钮时,我有这个错误信息:
Neither property "PermitsContractor" nor method "getPermitsContractor()" nor method "isPermitsContractor()" exists in class "Main\CoreBundle\Entity\PermitsRepository"
这是我的表格
public function buildForm(FormBuilderInterface $builder, array $options) {
$builder->add('PermitsContractor', 'entity', array(
'class' => 'MainCoreBundle:Generalcontractor',
'multiple' => false,
'expanded' => false,
'property'=>'name',
'label'=> 'Generalny wykonawca',
));
$builder->add('PermitsCompany', 'entity', array(
'class' => 'MainCoreBundle:Company',
'multiple' => false,
'expanded' => false,
'property'=>'name',
'label'=> 'Firma',
));
$builder->add('Permitname', 'text',array('label'=> "Imię", 'required'=>false));
$builder->add('Permitsurname', 'text',array('label'=> "Nazwisko", 'required'=>false));
$builder->add('expirationdate', 'date', array(
'widget' => 'single_text',
'label'=> 'Data ważności',
));
$builder->add('file', 'file', array('required'=>false, 'label'=>'Przeglądaj'));
}
public function getName() {
return 'main_admin_permits_type';
}
我结帐,我在实体中获得了吸气剂和制定者
答案 0 :(得分:2)
错误在这里
$perm = $permitsrepo->find($id);
$permitsrepo->setCreatedat($currentDate);
$permitsrepo->setPermitid($permitsidrand);
$permitsrepo->setPermitsSpot($spotEntity);
使用
$perm = $permitsrepo->find($id);
$perm->setCreatedat($currentDate);
$perm->setPermitid($permitsidrand);
$perm->setPermitsSpot($spotEntity);