0

好的,所以我正在使用 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))TimeClockReportType它工作得很好......但我看不到任何错误或为什么它不起作用..

4

1 回答 1

0

空白页表示发生了解析错误/引擎错误。我建议更改您的 php.ini 文件以启用 display_errors。

请务必在之后重新启动您的网络服务器。

于 2012-06-06T02:46:56.127 回答