" localhost页面无效"或Symfony 3的内存不足问题

时间:2017-04-11 16:16:21

标签: php symfony

我尝试使用复选框添加搜索页面以选择用户想要查找的内容。但是我继续geting localhost页面没有工作错误500或者关于内存不够的东西

  

允许的内存大小为536870912字节耗尽(尝试分配4096字节

我将php.ini更改为512M并且在它说134 ...字节之前我仍然遇到此错误。我重新启动并重置了所有内容。

这是我的代码: searchType页面:

namespace AppBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;


class SearchType extends AbstractType
{
    /**
     * @param FormBuilderInterface $builder
     * @param array $options
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('botanicalname', SearchType::class, array('label' => 'Botanical Name:'))
            ->add('commonname', SearchType::class, array('label' => 'Common Name:'))
            ->add('wetsoil', SearchType::class, array('label' => 'Tolerates Wet Soil:'))
            ->add('moistsoil', SearchType::class, array('label' => 'Prefers Moist Soil:'))
            ->add('peatysoil', SearchType::class, array('label' => 'Prefers Peaty Soil:'))
            ->add('welldrainedsoil', SearchType::class, array('label' => 'Prefers Well-drained Soil:'))
            ->add('drought', SearchType::class, array('label' => 'Tolerates Drought:'))
            ->add('claysoil', SearchType::class, array('label' => 'Tolerates Clay Soil:'))
            ->add('sandysoil', SearchType::class, array('label' => 'Prefers Sandy Soil:'))
            ->add('loamsoil', SearchType::class, array('label' => 'Prefers Loam Soil:'))
            ->add('infertilesoil', SearchType::class, array('label' => 'Tolerates Infertile Soil:'))
            ->add('richsoil', SearchType::class, array('label' => 'Prefers Rich Soil:'))
            ->add('compactedsoil', SearchType::class, array('label' => 'Tolerates Compacted Soil:'))
            ->add('cityconditions', SearchType::class, array('label' => 'Tolerates City Conditions:'))
            ->add('pollution', SearchType::class, array('label' => 'Tolerates Pollution:'))
            ->add('salt', SearchType::class, array('label' => 'Tolerates Salt Conditions:'))
            ->add('windy', SearchType::class, array('label' => 'Tolerates Windy Conditions:'))
            ->add('shade', SearchType::class, array('label' => 'Prefers Shade:'))
            ->add('partshade', SearchType::class, array('label' => 'Prefers Part Shade:'))
            ->add('fullsun', SearchType::class, array('label' => 'Prefers Full Sun:'))
            ->add('pestproblem', SearchType::class, array('label' => 'Pest Problem:'))
            ->add('phpreference', SearchType::class, array('label' => 'Pest Problem:'))
            ->add('borderlinehardy', SearchType::class, array('label' => 'BorderLine Hardy'))
            ->add('save', SubmitType::class, array('label' => 'Submit'));





    }

    /**
     * @param OptionsResolver $resolver
     */
    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => 'AppBundle\Entity\Shrubs'
        ));
    }

    /** * {@inheritdoc} */
    public function getBlockPrefix(){
        return 'appbundle_shrubs';}
}

控制器:

 /**
     * Creates a new Shrubs entity.
     *
     * @Route("/search", name="shrubs_search")
     * @Method({"GET", "POST"})
     */
    public function searchAction(Request $request)
    {

        $form = $this->createForm('AppBundle\Form\SearchType');
        $form->handleRequest($request);


        return $this->render('shrubs/search.html.twig', array(

            'form' => $form->createView(),
        ));
    }

我的搜索页面只有树枝形状的东西。有什么想法吗?

1 个答案:

答案 0 :(得分:1)

您有一个循环引用问题。您可以定义包含自身的表单类型SearchTyp$builder->add('...', SearchType::class, ...)。这是不可能的。如果我理解正确,那么您现在只需要一个包含复选框的表单。你可以像使用CheckboxTypTextType等那样使用symfony中的内置SubmitType(至少你有使用语句):

<?php

namespace AppBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType; # don't forget...


class SearchType extends AbstractType
{
    /**
     * @param FormBuilderInterface $builder
     * @param array $options
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('botanicalname', CheckboxType::class, array('label' => 'Botanical Name:'))
            ->add('commonname', CheckboxType::class, array('label' => 'Common Name:'))
            ->add('wetsoil', CheckboxType::class, array('label' => 'Tolerates Wet Soil:'))
            // ...
    }
    // ...
}