Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/256.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 具有稍微相似实体的不同行为_Php_Symfony_Registration - Fatal编程技术网

Php 具有稍微相似实体的不同行为

Php 具有稍微相似实体的不同行为,php,symfony,registration,Php,Symfony,Registration,我用Symfony2制作了一个web应用程序。有两种用户,UserOperator和UserGroundStation。它们都扩展了用户 用户地面站 namespace Acme\ManagementBundle\Entity; use Doctrine\ORM\Mapping as ORM; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Coll

我用Symfony2制作了一个web应用程序。有两种用户,
UserOperator
UserGroundStation
。它们都扩展了
用户

用户地面站
    namespace Acme\ManagementBundle\Entity;

    use Doctrine\ORM\Mapping as ORM;
    use Doctrine\Common\Collections\ArrayCollection;
    use Doctrine\Common\Collections\Collection;
    use PUGX\MultiUserBundle\Validator\Constraints\UniqueEntity;
    use Symfony\Component\Validator\Constraints as Assert;

    /**
     * @ORM\Entity
     * @ORM\HasLifecycleCallbacks()
     * @ORM\Table(name="user_GroundStation")
     * @UniqueEntity(fields = "username", targetClass = "Acme\ManagementBundle\Entity\User",         
    message="Username already_used")
     * @UniqueEntity(fields = "email", targetClass = "Acme\ManagementBundle\Entity\User", 
    message="Email already_used")
     */

    class UserGroundStation extends User
    {
        /**
         * @ORM\Id
         * @ORM\Column(type="integer")
         * @ORM\GeneratedValue(strategy="AUTO")
         */
        protected $id;
             /** 
         * @ORM\Column(type="string", length=60)
         * @var String
         */
        protected $name;
        /**
         * @var float
         *
         * @ORM\Column(name="latitude", type="float")
         */
        private $latitude;
        /**
         * @var float
         *
         * @ORM\Column(name="longitude", type="float")
         */
        private $longitude;

        /**
         * Set latitude
         *
         * @param string $latitude
         * @return UserGroundStation
         */
        public function setLatitude($latitude)
        {
            $this->latitude = $latitude;

            return $this;
        }

        /**
         * Get latitude
         *
         * @return string 
         */
        public function getLatitude()
        {
            return $this->latitude;
        }

        /**
         * Set longitude
         *
         * @param float $longitude
         * @return UserGroundStation
         */
        public function setLongitude($longitude)
        {
            $this->longitude = $longitude;   
            return $this;
        }
        /**
         * Get longitude
         *
         * @return float 
         */
        public function getLongitude()
        {
            return $this->longitude;
        }
        /**
         * @ORM\PrePersist
         */
        public function setCreatedAtValue()
        {
            $this->addRole('ROLE_GS');
        }       
    }
用户操作员

它们扩展了
用户

当我为
UserOperator
调用注册页面时,它会工作;当我为
UserGroundStation
调用注册页面时,Symfony会提醒我:

属性“mission”或方法“getMission()”、“isMission()”、“hasMission()”、“\uu get()”中的任何一个都不存在,并且在类“Acme\ManagementBundle\Entity\UserGroundStation”中都没有公共访问权限

怎么可能呢?我在哪里可以找到错误

使用者


这真是个愚蠢的问题

它们有不同的表单类型:

RegistrationUserOperatorFormType不同于RegistrationUserGroundStationFormType和
ProfileUserGroundStationFormType与ProfileUserOperatorFormType不同。

您应该发布
User
类的内容;听上去,您没有正确实现多关系所需的接口。过去,我在扩展基本实体时遇到了许多问题。尝试将这些方法也放在
UserGroundStation
中。至少带有
parent::method()
的方法在它们内部调用,只是为了看看这是否是层次结构问题。
  namespace Acme\ManagementBundle\Entity;

  use Doctrine\ORM\Mapping as ORM;
  use Doctrine\Common\Collections\ArrayCollection;
  use Doctrine\Common\Collections\Collection;
  use PUGX\MultiUserBundle\Validator\Constraints\UniqueEntity;
  use Symfony\Component\Validator\Constraints as Assert;

  /**
   * @ORM\Entity
   * @ORM\HasLifecycleCallbacks()
   * @ORM\Table(name="user_Operator")
   * @UniqueEntity(fields = "username", targetClass = "Acme\ManagementBundle\Entity\User", 
   message="Username already_used")
   * @UniqueEntity(fields = "email", targetClass = "Acme\ManagementBundle\Entity\User", 
   message="Email already_used")
   */

  class UserOperator extends User
  {
      /**
       * @ORM\Id
       * @ORM\Column(type="integer")
       * @ORM\GeneratedValue(strategy="AUTO")
       */
      protected $id;
       /** 
       * @ORM\Column(type="string", length=60)
       * @var String
       */
      protected $name;
       /**
       * @ORM\PrePersist
       */
      public function setCreatedAtValue()
      {
          $this->addRole('ROLE_OPERATOR');
      }    
  }
  namespace Acme\ManagementBundle\Entity;

  use Doctrine\ORM\Mapping as ORM;
  use FOS\UserBundle\Model\User as BaseUser;
  use Doctrine\Common\Collections\ArrayCollection;
  use Doctrine\Common\Collections\Collection;


  /**
   * @ORM\Entity
   * @ORM\Table(name="user")
   * @ORM\InheritanceType("JOINED")
   * @ORM\DiscriminatorColumn(name="type", type="string")
   * @ORM\DiscriminatorMap({"user_one" = "UserGroundStation", "user_two" = "UserOperator"})
   * @ORM\MappedSuperclass()
   *
   */
  abstract class User extends BaseUser
  {
      /**
       * @ORM\Id
       * @ORM\Column(type="integer")
       * @ORM\GeneratedValue(strategy="AUTO")
       */
      protected $id;
          /**
       * @ORM\ManyToMany(targetEntity="Acme\ManagementBundle\Entity\Mission", mappedBy="users")
       */
      protected $missions;

      public function __construct(){
          $this -> missions = new ArrayCollection();
      }

      public function setMissions(Collection $missions){
          $this -> missions = $missions;
          return $this;
      }

      public function addMission($mission){
          $this -> missions -> add($mission);
          return $this;
      }

      public function getMissions(){
          return $this -> missions;
      }