好的,所以我正在使用symfony2,我正在尝试在此表单中创建一个基于另一个实体的选项框...
所以在我的控制器里我有:
<?php
namespace Ecs\CrmBundle\Controller\Report;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Ecs\CrmBundle\Form\Report\TimeClockReportType;
class TimeClockReportController extends Controller
{
public function indexAction()
{
$request = $this->get('request');
$em = $this->getDoctrine()->getEntityManager();
$start = null;
$end = null;
$dateRangeForm = $this->createForm(new TimeClockReportType());
if ($request->getMethod() == 'POST')
{
$dateRangeForm->bindRequest($request);
$formData = $dateRangeForm->getData();
$start = $formData['dateRange']['startDate'];
$end = $formData['dateRange']['endDate'];
}
return $this->render('EcsCrmBundle:Reports:TimeClockReport.html.twig', array(
'start' => $start,
'end' => $end,
'form' => $dateRangeForm->createView(),
));
}
}
和我的TimeClockReportType.php看起来像:
<?php
namespace Ecs\CrmBundle\Form\Report;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilder;
use Ecs\CrmBundle\Form\Parts\DateRangeType;
use Ecs\CrmBundle\Form\Parts\DepartmentSelectionType;
class TimeClockReportType extends AbstractType
{
public function buildForm(FormBuilder $builder, array $options)
{
$builder
->add('dateRange', new DateRangeType())
->add('salesCompany', new DepartmentSelectionType(true));
}
public function getName()
{
return 'ecs_crmbundle_TimeClockReportType';
}
}
我的DepartmentSelectionType如下所示:
<?php
namespace Ecs\CrmBundle\Form\Parts;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilder;
class DepartmentSelectionType extends AbstractType
{
private $canSeeAll = false;
public function __construct($canSeeAll = false)
{
$this->canSeeAll = $canSeeAll;
}
public function buildForm(FormBuilder $builder, array $options)
{
$builder
->add('department', 'entity',
array(
'class' => "EcsAgentManagerBundle:EmployeeDepartment",
'required' => false,
'multiple' => true,
'expanded' => true,
'label' => "Department"))
;
}
public function getDefaultOptions(array $options)
{
return array(
'data_class' => 'Ecs\AgentManagerBundle\Entity\EmployeeDepartment',
);
}
public function getName()
{
return 'ecs_crmbundle_departmentselectiontype';
}
}
我想出的问题是,我只是一个空白的白色屏幕......但是,如果我删除了:
来自->add('salesCompany', new DepartmentSelectionType(true))
的{p> TimeClockReportType
它工作得很好......但我看不出任何错误或为什么它不起作用..
答案 0 :(得分:0)
空白页表示发生了解析错误/引擎错误。我建议改变你的php.ini文件以打开display_errors。
请务必在以后重启您的网络服务器。