如何将供应商模型摘要 class 扩展到实体中

How to extend a vendor model abstract class into an entity

基于 FOSUserbundle 的方法,我制作了一个供应商包,其中包含一个 Analytic Abstrakt class 而不是实现一个 AnalyticInterface 并且在一个 src/AppBundle 中,我(有一个分析实体扩展供应商分析摘要 class 但这不起作用,我的实体没有抽象 class 属性($referer, $host, $ip, $browser, ...)

界面:

  <?php
/**
 * Created by PhpStorm.
 * User: VanIllaSkyPE
 * Date: 01/11/2016
 * Time: 23:26
 */

namespace Gkratz\AnalyticBundle\Model;


/**
 * Interface AnalyticInterface
 * @package Gkratz\AnalyticBundle\Model
 */
interface AnalyticInterface
{
    /**
     * Set date
     *
     * @param \DateTime $date
     * @return Analytic
     */
    public function setDate($date);

    /**
     * Get date
     *
     * @return \DateTime
     */
    public function getDate();

    /**
     * Set page
     *
     * @param string $page
     * @return Analytic
     */
    public function setPage($page);

    /**
     * Get page
     *
     * @return string
     */
    public function getPage();

    /**
     * Set ip
     *
     * @param string $ip
     * @return Analytic
     */
    public function setIp($ip);

    /**
     * Get ip
     *
     * @return string
     */
    public function getIp();

    /**
     * Set host
     *
     * @param string $host
     * @return Analytic
     */
    public function setHost($host);

    /**
     * Get host
     *
     * @return string
     */
    public function getHost();

    /**
     * Set browser
     *
     * @param string $browser
     * @return Analytic
     */
    public function setBrowser($browser);

    /**
     * Get browser
     *
     * @return string
     */
    public function getBrowser();

    /**
     * Set referer
     *
     * @param string $referer
     * @return Analytic
     */
    public function setReferer($referer);

    /**
     * Get referer
     *
     * @return string
     */
    public function getReferer();

    /**
     * Set newSession
     *
     * @param boolean $newSession
     * @return Analytic
     */
    public function setNewSession($newSession);

    /**
     * Get newSession
     *
     * @return boolean
     */
    public function getNewSession();
}

基础摘要class:

<?php

/**
 * Created by PhpStorm.
 * User: VanIllaSkyPE
 * Date: 01/11/2016
 * Time: 22:30
 */

namespace Gkratz\AnalyticBundle\Model;

/**
 * Class Analytic
 * @package Gkratz\AnalyticBundle\Model
 */
abstract class Analytic implements AnalyticInterface
{
    protected $id;

    /**
     * @var \DateTime
     */
    protected $date;

    /**
     * @var string
     */
    protected $page;

    /**
     * @var string
     */
    protected $ip;

    /**
     * @var string
     */
    protected $host;

    /**
     * @var string
     */
    protected $browser;

    /**
     * @var string
     */
    protected $referer;

    /**
     *
     * @var boolean
     */
    protected $newSession;



    public function __construct()
    {
        $this->date = new \Datetime();
    }


    /**
     * Get id
     *
     * @return integer
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set date
     *
     * @param \DateTime $date
     * @return Analytic
     */
    public function setDate($date)
    {
        $this->date = $date;

        return $this;
    }

    /**
     * Get date
     *
     * @return \DateTime
     */
    public function getDate()
    {
        return $this->date;
    }

    /**
     * Set page
     *
     * @param string $page
     * @return Analytic
     */
    public function setPage($page)
    {
        $this->page = $page;

        return $this;
    }

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

    /**
     * Set ip
     *
     * @param string $ip
     * @return Analytic
     */
    public function setIp($ip)
    {
        $this->ip = $ip;

        return $this;
    }

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

    /**
     * Set host
     *
     * @param string $host
     * @return Analytic
     */
    public function setHost($host)
    {
        $this->host = $host;

        return $this;
    }

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

    /**
     * Set browser
     *
     * @param string $browser
     * @return Analytic
     */
    public function setBrowser($browser)
    {
        $this->browser = $browser;

        return $this;
    }

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

    /**
     * Set referer
     *
     * @param string $referer
     * @return Analytic
     */
    public function setReferer($referer)
    {
        $this->referer = $referer;

        return $this;
    }

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

    /**
     * Set newSession
     *
     * @param boolean $newSession
     * @return Analytic
     */
    public function setNewSession($newSession)
    {
        $this->newSession = $newSession;

        return $this;
    }

    /**
     * Get newSession
     *
     * @return boolean
     */
    public function getNewSession()
    {
        return $this->newSession;
    }
}

应用分析实体:

<?php

namespace AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Gkratz\AnalyticBundle\Model\Analytic as BaseAnalytic;

/**
 * Analytic
 *
 * @ORM\Table(name="analytic")
 * @ORM\Entity(repositoryClass="AppBundle\Repository\AnalyticRepository")
 */
class Analytic extends BaseAnalytic
{
    /**
     * @var int
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;


    /**
     * Get id
     *
     * @return int
     */
    public function getId()
    {
        return $this->id;
    }

    public function __construct()
    {
        parent::__construct();
    }
}

感谢您的任何回复

抽象 class Analytic 仅定义属性。

Analytic 如果您想将它们用作数据库列,则需要用 @ORM\Column(...) 注释它们。

另见:http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/inheritance-mapping.html