在'Subject \ Entity \ Subject#users'中找不到目标实体User \ Entity \ User

时间:2013-02-07 13:02:38

标签: php doctrine-orm zend-framework2

这是我的代码,我试图映射

这是我的user.php

 <?php

namespace User\Entity;

 use Doctrine\ORM\Mapping as ORM;
 use Zend\InputFilter\InputFilter;
    use Zend\InputFilter\Factory as InputFactory;
 use Zend\InputFilter\InputFilterAwareInterface;
use Zend\InputFilter\InputFilterInterface;

 /**
 * @ORM\Entity

* @ORM\Table(name="users")

* @property string $user_name

* @property string $pass_word

* @property int $id

*/
class User implements InputFilterAwareInterface {

 protected $inputFilter;
/**
 * @ORM\ManyToMany(targetEntity="Subject\Entity\Subject", inversedBy="users")
 * @JoinTable(name="users_subjects")
 * @var Collection
 */
protected $userName;
protected $password;
private $subjects;
/** @ORM\Id() @ORM\Column(type="integer") @ORM\GeneratedValue(strategy="AUTO") @var int */
protected $id;

public function __get($property) {

    return $this->$property;
}

public function __construct() {
    $this->subjects = new \Doctrine\Common\Collections\ArrayCollection();
}

/**
 * Magic setter to save protected properties.
 *
 * @param string $property
 * @param mixed $value
 */
public function __set($property, $value) {

    $this->$property = $value;
}

/**
 * Convert the object to an array.
 *
 * @return array
 */
public function getArrayCopy() {

    return get_object_vars($this);
}

public function populate($data = array()) {
    $this->id = $data['id'];
    $this->userName = $data['userame'];
    $this->password = $data['password '];
}

public function setInputFilter(InputFilterInterface $inputFilter) {
    throw new \Exception("Not used");
}

public function getInputFilter() {
    if (!$this->inputFilter) {
        $inputFilter = new InputFilter();
        $inputFactory = new InputFactory();

        $inputFilter->add($inputFactory->createInput(array('name' => 'id',
                    'required' => true,
                    'filters' => array(
                        array('name' => 'Int'),
                        ))));
        $inputFilter->add($inputFactory->createInput(array('name' => 'Username',
                    'required' => true,
                    'filters' => array(
                        array('name' => 'StripTags'),
                        array('name' => 'StringTrim'),
                    ),
                    'validators' => array(
                        array(
                            'name' => 'StringLength',
                            'options' => array(
                                'encoding' => 'UTF-8',
                                'min' => 1,
                                'max' => 100,
                            ),
                        ),
                    ),
                )));
        $inputFilter->add($inputFactory->createInput(array('name' => 'Password',
                    'required' => true,
                    'filters' => array(
                        array('name' => 'StripTags'),
                        array('name' => 'StringTrim'),
                    ),
                    'validators' => array(
                        array(
                            'name' => 'StringLength',
                            'options' => array(
                                'encoding' => 'UTF-8',
                                'min' => 1,
                                'max' => 100,
                            ),
                        ),
                    ),
                )));
        $this->inputFilter = $inputFilter;
    }

    return $this->inputFilter;
}

//put your code here
}

?>

这就是我的主题.php

<?php

  namespace Subject\Entity;

  use Doctrine\ORM\Mapping as ORM;
  use Zend\InputFilter\InputFilter;
  use Zend\InputFilter\Factory as InputFactory;
  use Zend\InputFilter\InputFilterAwareInterface;
  use Zend\InputFilter\InputFilterInterface;

 /**
 *

 * @ORM\Entity

 * @ORM\Table(name="subject")

 * @property string $subjectname

 * @property int $users

 * @property int $id

  */
 class Subject implements InputFilterAwareInterface {

protected $inputFilter;
/**

 * @ORM\Id

 * @ORM\Column(type="integer");

 * @ORM\GeneratedValue(strategy="AUTO")

 */
protected $id;
/**

 * @ORM\Column(type="string")

 */
protected $subjectname;
/**
 * @ORM\ManyToMany(targetEntity="User\Entity\User", mappedBy="subjects")
 */
protected $users;

public function __construct() {
    $this->users = new \Doctrine\Common\Collections\ArrayCollection();
    $this->addUser($this->users);
}

/** @return User|null */
public function getUsers() {
    return $this->users;
}

/** @param User $user */
public function addUser(User $user) {
    if ($users !== null || $user instanceof User) {
        $this->users->add($users);
    } else {
        throw new InvalidArgumentException('$user must be instance of Entity\User or null!');
    }
}

/**

 * Magic getter to expose protected properties.

 *

 * @param string $property

 * @return mixed

 */
public function __get($property) {

    return $this->$property;
}

/**

 * Magic setter to save protected properties.

 *

 * @param string $property

 * @param mixed $value

 */
public function __set($property, $value) {

    $this->$property = $value;
}

/**

 * Convert the object to an array.

 *

 * @return array

 */
public function getArrayCopy() {

    return get_object_vars($this);
}

/**

 * Populate from an array.

 *

 * @param array $data

 */
public function populate($data = array()) {

    $this->id = $data['id'];

    $this->subjectname = $data['subjectname'];

    $this->users = $data['user_id'];
    //print_r($data);
}

public function setInputFilter(InputFilterInterface $inputFilter) {

    throw new \Exception("Not used");
}

public function getInputFilter() {

    if (!$this->inputFilter) {
        $inputFilter = new InputFilter();
        $factory = new InputFactory();
        $inputFilter->add($factory->createInput(array(
                    'name' => 'id',
//                        'required' => true,
                    'filters' => array(
                        array('name' => 'Int'),
                    ),
                )));
        $inputFilter->add($factory->createInput(array(
                    'name' => 'subjectname',
                    'required' => true,
                    'filters' => array(
                        array('name' => 'StripTags'),
                        array('name' => 'StringTrim'),
                    ),
                    'validators' => array(
                        array(
                            'name' => 'StringLength',
                            'options' => array(
                                'encoding' => 'UTF-8',
                                'min' => 1,
                                'max' => 100,
                            ),
                        ),
                    ),
                )));



        $inputFilter->add($factory->createInput(array(
                    'name' => 'users',
                    'required' => true,
                    'filters' => array(
                        array('name' => 'Int'),
                    ),
                )));



        $this->inputFilter = $inputFilter;
    }



    return $this->inputFilter;
  }

 }

由于我将许多映射到很多我不知道为什么我会收到此错误

  

“在'Subject \ Entity \ Subject#users'中找不到目标实体User \ Entity \ User。”

0 个答案:

没有答案