我一直在遵循本教程:tutorial.symblog.co.uk,刚刚完成了第 2 部分。我还遵循了其中一位用户在评论中所说的关于本教程中已弃用的函数的内容,并在代码中修复了这些函数。
但是,当我尝试提交表单时,我仍然收到以下错误:
ContextErrorException: 注意: 未定义的变量:/private_html/symfony/symblog/src/Blogger/BlogBundle/Entity/Query.php第22行中的名称
我已经查看了我的查询.php文件,但没有找到任何东西。
在这里:
<?php
// src/Blogger/BlogBundle/Entity/Enquiry.php
namespace BloggerBlogBundleEntity;
use SymfonyComponentValidatorMappingClassMetadata;
use SymfonyComponentValidatorConstraintsNotBlank;
use SymfonyComponentValidatorConstraintsEmail;
use SymfonyComponentValidatorConstraintsLength;
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)));
}
}
提前感谢!
你忘了将参数传递给你的 setter
public function setName($name) {
$this->name = $name;
}