1
FOSUserbundleからの操作方法に基づいて、AnalyticInterfaceを実装するよりもAnalytic Abstraktクラスを含むベンダーバンドルを作成しました。src/AppBundle、私のエンティティは、抽象クラスのプロパティ($ 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();
}
基本抽象クラス:
<?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;
}
}
のApp分析エンティティは:
<?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();
}
}
は応答
A、それが問題だった、MANありがとうありがとうありがとうありがとうREALLY BIG –