【发布时间】:2013-12-23 22:57:34
【问题描述】:
我一直在关注本教程:tutorial.symblog.co.uk,并且刚刚完成了第 2 部分。我还关注了一位用户在 cmets 中所说的关于教程中不推荐使用的函数的内容,并在我的代码。
但是,当我尝试提交表单时,我仍然收到以下错误:
ContextErrorException:注意:未定义变量:/private_html/symfony/symblog/src/Blogger/BlogBundle/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)));
}
}
提前致谢!
【问题讨论】:
标签: php symfony entity deprecated getter-setter