symfony2联系人表单在呈现到查看页面时出错

symfony2联系人表单在呈现到查看页面时出错,symfony,Symfony,嘿,我是这个symfony2框架的新手,所以我需要一些帮助 这是一个联系人表单的代码,当我试图将表单呈现到查看页面时,它会出现一些错误,请参见下面的代码和错误 如果有人知道可能是什么问题,请告诉我 谢谢 ContactType.php <?php // src/Aleksandar/IntelMarketingBundle/Resources/views/ContactType.php namespace Aleksandar\IntelMarketingBundle\Form\Ty

嘿,我是这个symfony2框架的新手,所以我需要一些帮助

这是一个联系人表单的代码,当我试图将表单呈现到查看页面时,它会出现一些错误,请参见下面的代码和错误

如果有人知道可能是什么问题,请告诉我

谢谢

ContactType.php

   <?php
// src/Aleksandar/IntelMarketingBundle/Resources/views/ContactType.php
namespace Aleksandar\IntelMarketingBundle\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Symfony\Component\Validator\Constraints\Email;
use Symfony\Component\Validator\Constraints\Length;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Constraints\Collection;


class ContactType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('name', 'text', array(
                'attr' => array(
                    'placeholder' => 'What\'s your name?',
                    'pattern'     => '.{2,}' //minlength
                )
            ))
            ->add('email', 'email', array(
                'attr' => array(
                    'placeholder' => 'So I can get back to you.'
                )
            ))
            ->add('subject', 'text', array(
                'attr' => array(
                    'placeholder' => 'The subject of your message.',
                    'pattern'     => '.{3,}' //minlength
                )
            ))
            ->add('message', 'textarea', array(
                'attr' => array(
                    'cols' => 20,
                    'rows' => 2,
                    'placeholder' => 'And your message to me...'
                )
            ));
    }

    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $collectionConstraint = new Collection(array(
            'name' => array(
                new NotBlank(array('message' => 'Name should not be blank.')),
                new Length(array('min' => 2))
            ),
            'email' => array(
                new NotBlank(array('message' => 'Email should not be blank.')),
                new Email(array('message' => 'Invalid email address.'))
            ),
            'subject' => array(
                new NotBlank(array('message' => 'Subject should not be blank.')),
                new Length(array('min' => 3))
            ),
            'message' => array(
                new NotBlank(array('message' => 'Message should not be blank.')),
                new Length(array('min' => 5))
            )
        ));

        $resolver->setDefaults(array(
            'constraints' => $collectionConstraint
        ));
    }

    public function getName()
    {
        return 'contact';
    }
}
?>
以及视图文件夹中的contact.html.php

<?php echo $view['form']->form($form) ?>
我的看法

<!-- app/Resources/views/contact.html.php -->
<!DOCTYPE html>
<html>
    <head><?php echo $view->render('AleksandarIntelMarketingBundle:template:head.html.php') ?></head>
<body>
    <div class="wrapper">
        <div id="header"><?php echo $view->render('AleksandarIntelMarketingBundle:template:header.html.php') ?></div>
            <div id="leftside"><?php echo $view->render('AleksandarIntelMarketingBundle:template:leftside.html.php') ?></div>
            <div id="rightside"><?php echo $view->render('AleksandarIntelMarketingBundle:template:rightside.html.php') ?>
                <div class="container">



                    </div>
                    <script type="text/javascript">
                         $(document).ready(function () {
                             if (!$.browser.webkit) {
                                $('.container').jScrollPane();
                                                    }
                                                         });
                    </script>
            <div id="clear"></div>
            </div>
    <div id="footer">
    <?php echo $view->render('AleksandarIntelMarketingBundle:template:footer.html.php') ?>
    </div>
        </div>
</body>
</html>

$(文档).ready(函数(){
如果(!$.browser.webkit){
$('.container').jScrollPane();
}
});

您需要将
表单
添加到此块:

$this->renderView('AleksandarIntelMarketingBundle::contact.html.php', array(
    'ip'      => $request->getClientIp(),
    'name'    => $form->get('name')->getData(),
    'message' => $form->get('message')->getData(),
    'form'    => $form->createView(),
));
我还注意到你有

return$this->render('AleksandarIntelMarketingBundle::contact.html.php')


作为
contactAction
方法中的第一行。应该删除,因为你的代码不会使它超过这一行,它只是返回视图。

我做的比我删除第一行时,你提到它得到空白页现在错误只是空白页喜欢它自动创建其他联系页面..改变你的模板注释为:<代码> @模板(“AleksandarIntelMarketingBundle::contact.html.php”)
现在我得到了这个[语法错误]预期的条令\Common\Annotations\DocLexer::T_CLOSE_括号,在Aleksandar\IntelMarketingBundle\Controller\DefaultController::contactAction()方法的第49位得到了'AleksandarIntelMarketingBundle::contact'。我忘记添加了”最后,仔细检查注释,确保包含右括号。
 Notice: Undefined variable: form in C:\wamp\www\symfony\src\Aleksandar\IntelMarketingBundle\Resources\views\contact.html.php line 1
500 Internal Server Error - ContextErrorException 
<!-- app/Resources/views/contact.html.php -->
<!DOCTYPE html>
<html>
    <head><?php echo $view->render('AleksandarIntelMarketingBundle:template:head.html.php') ?></head>
<body>
    <div class="wrapper">
        <div id="header"><?php echo $view->render('AleksandarIntelMarketingBundle:template:header.html.php') ?></div>
            <div id="leftside"><?php echo $view->render('AleksandarIntelMarketingBundle:template:leftside.html.php') ?></div>
            <div id="rightside"><?php echo $view->render('AleksandarIntelMarketingBundle:template:rightside.html.php') ?>
                <div class="container">



                    </div>
                    <script type="text/javascript">
                         $(document).ready(function () {
                             if (!$.browser.webkit) {
                                $('.container').jScrollPane();
                                                    }
                                                         });
                    </script>
            <div id="clear"></div>
            </div>
    <div id="footer">
    <?php echo $view->render('AleksandarIntelMarketingBundle:template:footer.html.php') ?>
    </div>
        </div>
</body>
</html>
$this->renderView('AleksandarIntelMarketingBundle::contact.html.php', array(
    'ip'      => $request->getClientIp(),
    'name'    => $form->get('name')->getData(),
    'message' => $form->get('message')->getData(),
    'form'    => $form->createView(),
));