Question

I have been following this tutorial: tutorial.symblog.co.uk, and just finished up Part 2. I also followed what one of the users said in the comments about the deprecated functions that were part of the tutorial, and I fixed those in my code.

However, I still get the following error when I try to submit my form:

ContextErrorException: Notice: Undefined variable: name in /private_html/symfony/symblog/src/Blogger/BlogBundle/Entity/Enquiry.php line 22

I've looked through my Enquiry.php file, but haven't found anything.

Here it is:

<?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)));
    }
}

Thanks in advance!

Was it helpful?

Solution

You forgot to pass the parameter into your setter

public function setName($name) {
    $this->name = $name;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top