Enquiry.php中未定义的变量“name”(Symfony2)

时间:2013-12-23 22:57:34

标签: php symfony entity deprecated getter-setter

我一直在关注本教程:tutorial.symblog.co.uk,刚刚完成了第2部分。我还关注了其中一位用户在评论中对教程中已弃用的函数所说的内容,并修复了这些内容。在我的代码中。

但是,当我尝试提交表单时仍然出现以下错误:

ContextErrorException:注意:未定义的变量:/private_html/symfony/symblog/src/Blogger/BlogBu​​ndle/Entity/Enquiry.php第22行中的名称

我查看了我的Enquiry.php文件,但没有找到任何内容。

这是:

<?php
// src/Blogger/BlogBundle/Entity/Enquiry.php

namespace Blogger\BlogBundle\Entity;

use Symfony\Component\Validator\Mapping\ClassMetadata;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Constraints\Email;
use Symfony\Component\Validator\Constraints\Length;

class Enquiry {
    protected $name;
    protected $email;
    protected $subject;
    protected $body;

    public function getName() {
        return $this->name;
    }

    public function setName() {
        $this->name = $name; // Line 22
    }

    public function getEmail() {
        return $this->email;
    }

    public function setEmail() {
        $this->email = $email;
    }

    public function getSubject() {
        return $this->subject;
    }

    public function setSubject() {
        $this->subject = $subject;
    }

    public function getBody() {
        return $this->body;
    }

    public function setBody() {
        $this->body = $body;
    }

    public static function loadValidatorMetadata(ClassMetadata $metadata) {
        $metadata->addPropertyConstraint('name', new NotBlank())
            ->addPropertyConstraint('email', new Email())
            ->addPropertyConstraint('subject', new NotBlank())
            ->addPropertyConstraint('subject', new Length(array('max'=>50)))
            ->addPropertyConstraint('body', new Length(array('min'=>50)));
    }
}

提前致谢!

1 个答案:

答案 0 :(得分:1)

您忘记将参数传递到您的setter

public function setName($name) {
    $this->name = $name;
}