【发布时间】:2017-10-23 14:04:02
【问题描述】:
我正在使用 symfony 2.5 和 Php 5.3(旧服务器)
我只想在我的表单中添加一个输入文件以显示他的路径名,例如 (C://pathto/filename)
我在我的类 Advert.php 中添加了一个属性:
/**
* @ORM\Column(type="string", nullable=true)
*
*/
private $brochure = null;
public function getBrochure()
{
return $this->brochure;
}
public function setBrochure($brochure)
{
$this->brochure = $brochure;
return $this;
}
在我的 AdvertType.php 中:
->add('brochure', 'file', array(
'required' => false,))
但我认为我在 addAction 中遗漏了一些东西,因为它返回了一条错误的路径,例如:(/tmp/phpYAVwMQ) 而不是 (C://filename.pdf) 当显示{{ advert.brochure }}时
public function addAction(Request $request)
{
$advert = new Advert();
$form = $this->createForm(new AdvertType(), $advert);
$usr = $this->get('security.context')->getToken()->getUser();
if ($form->handleRequest($request)->isValid()) {
$em = $this->getDoctrine()->getManager();
$advert->setAuthor($usr->getUsername());
$advert->setDate(new \DateTime);
$em->persist($advert);
$em->flush();
$request->getSession()->getFlashBag()->add('info', 'Annonce bien enregistrée.');
// On redirige vers la page de visualisation de l'annonce nouvellement créée/
return $this->redirect($this->generateUrl('info_view', array('id' => $advert->getId())));
}
return $this->render('SocietyPerfclientBundle:Default:add.html.twig', array(
'form' => $form->createView(),
));
}
请帮帮我:)
【问题讨论】:
标签: symfony input path filenames