一个在本地服务器(XAMPP)上运行良好的网站,但在被移动到实时托管后,Doctrine会抛出错误(仅在网站上的一个位置),作为对POSTER请求的响应:
PHP Warning: require(/tmp/__CG__EntitiesEcomProducts.php): failed to open stream: No such file or directory in [SERVER PATH]/php/Vendors/doctrine/common/lib/Doctrine/Common/Proxy/AbstractProxyFactory.php on line 223
[24-Jan-2018 23:51:50 UTC] PHP Fatal error: require(): Failed opening required '/tmp/__CG__EntitiesEcomProducts.php' (include_path='.:/opt/alt/php71/usr/share/pear') in [SERVER PATH]/php/Vendors/doctrine/common/lib/Doctrine/Common/Proxy/AbstractProxyFactory.php on line 223
与托管管理员核对所有权限。
我不使用Symfony。
主机上的PHP版本在本地主机和实时主机上都是7.1。
UPD2。
抛出错误并不是特定的实体 - 它们中的所有@ManyToOne
关系都是如此。
UPD。 我将代码缩减为初始化Doctrine并运行与错误跟踪相同的代码:
$ItemOption= $this->EntityManager->getRepository($this->Settings->Ecom->get('repos')[3])->findOneById(1);
然后该实体抛出错误:
class EcomProductsPrices{
/** @Id @Column(type="integer") @GeneratedValue **/
protected $id;
/** @Column(type="string") **/
protected $title;
/** @Column(type="float",nullable=TRUE) **/
protected $price;
/** @Column(type="float",nullable=TRUE) **/
protected $discount;
/** @Column(type="integer",nullable=TRUE) **/
protected $discountAfter;
/**
* @ManyToOne(targetEntity="EcomProducts", inversedBy="EcomProductsPrices",cascade={ "persist"} )
*
**/
protected $EcomProducts;
/**
* @OneToMany(targetEntity="EcomCart", mappedBy="EcomProductsPrices",cascade={ "persist"} )
**/
protected $EcomCart;
public function __construct() {
$this->EcomCart = new \Doctrine\Common\Collections\ArrayCollection();
}
public function getId(){
return $this->id;
}
public function getTitle(){
return $this->title;
}
public function setTitle($title){
$this->title = $title;
}
public function getPrice(){
return $this->price;
}
public function setPrice($price=NULL){
$this->price = $price;
}
public function getDiscount(){
return $this->discount;
}
public function setDiscount($discount=NULL){
$this->discount = $discount;
}
public function getDiscountAfter(){
return $this->discountAfter;
}
public function setDiscountAfter($discountAfter=NULL){
$this->discountAfter = $discountAfter;
}
public function getEcomProducts(){
return $this->EcomProducts;
}
public function setEcomProducts(EcomProducts $EcomProducts){
$this->EcomProducts = $EcomProducts;
}
public function RemoveEcomProducts(EcomProducts $EcomProducts){
$this->EcomProducts=NULL;
}
public function clearEcomProducts(){
$this->EcomProducts->clear();
}
public function getEcomCart(){
return $this->EcomCart;
}
public function setEcomCart(EcomCart $EcomCart){
if(is_array($EcomCart)){
foreach($EcomCart as $Join){
if(is_int($Join)){
$Join=$this->Kernel->EntityManager->getRepository($this->Kernel->Settings->ICatcher->get('php.entities-namespaces')[0].'EcomCart')->findOneById($Join);
}
if(!$this->EcomCart->contains($EcomCart)){
$this->EcomCart[] = $EcomCart;
$EcomCart->setEcomProductsPrices($this);
}
}
}
else{
if(!$this->EcomCart->contains($EcomCart)){
$this->EcomCart[] = $EcomCart;
$EcomCart->setEcomProductsPrices($this);
}
}
}
public function RemoveEcomCart(EcomCart $EcomCart){
if($this->EcomCart->contains($EcomCart)){
$this->EcomCart->removeElement($EcomCart);
$EcomCart->RemoveEcomProductsPrices($this);
}
}
public function clearEcomCart(){
$this->EcomCart->clear();
}
/** @PrePersist */
public function preCreate(){
}
/** @preUpdate */
public function preUpdate(){
}
/** @preRemove */
public function preRemove(){
}
}
错误与加入EcomProducts有关 - 这就是Doctrine AbstractProxyFactor
但是当我更改为在此实体中找到一个时 - 没有错误:
class EcomOrder{
/** @Id @Column(type="integer") @GeneratedValue **/
protected $id;
/** @Column(type="string",nullable=TRUE) **/
protected $fullName;
/** @Column(type="string",nullable=TRUE) **/
protected $address1;
/** @Column(type="string",nullable=TRUE) **/
protected $address2;
/** @Column(type="string",nullable=TRUE) **/
protected $promocode;
/** @Column(type="string",nullable=TRUE) **/
protected $postcode;
/** @Column(type="float",nullable=TRUE) **/
protected $deliveryPrice;
/** @Column(type="boolean",nullable=TRUE) **/
protected $paid;
/** @Column(type="boolean",nullable=TRUE) **/
protected $paypalReturned;
/** @Column(type="boolean",nullable=TRUE) **/
protected $delivered;
/** @Column(type="datetime",nullable=TRUE) **/
protected $dateCreated;
/** @Column(type="datetime",nullable=TRUE) **/
protected $dateUpdated;
/**
* @OneToMany(targetEntity="EcomCart", mappedBy="EcomOrder",cascade={ "persist"} )
**/
protected $EcomCart;
public function __construct() {
$this->EcomCart = new \Doctrine\Common\Collections\ArrayCollection();
}
public function getId(){
return $this->id;
}
public function getFullName(){
return $this->fullName;
}
public function setFullName($fullName=NULL){
$this->fullName = $fullName;
}
public function getAddress1(){
return $this->address1;
}
public function setAddress1($address1=NULL){
$this->address1 = $address1;
}
public function getAddress2(){
return $this->address2;
}
public function setAddress2($address2=NULL){
$this->address2 = $address2;
}
public function getPromocode(){
return $this->promocode;
}
public function setPromocode($promocode=NULL){
$this->promocode = $promocode;
}
public function getPostcode(){
return $this->postcode;
}
public function setPostcode($postcode=NULL){
$this->postcode = $postcode;
}
public function getDeliveryPrice(){
return $this->deliveryPrice;
}
public function setDeliveryPrice($deliveryPrice=NULL){
$this->deliveryPrice = $deliveryPrice;
}
public function getPaid(){
return $this->paid;
}
public function setPaid($paid=NULL){
$this->paid = $paid;
}
public function getPaypalReturned(){
return $this->paypalReturned;
}
public function setPaypalReturned($paypalReturned=NULL){
$this->paypalReturned = $paypalReturned;
}
public function getDelivered(){
return $this->delivered;
}
public function setDelivered($delivered=NULL){
$this->delivered = $delivered;
}
public function getDateCreated(){
return $this->dateCreated;
}
public function setDateCreated($dateCreated=NULL){
if($dateCreated==NULL){
$this->dateCreated = new \DateTime("now", new \DateTimeZone('Europe/London'));
}
else{
$this->dateCreated=$dateCreated;
}
}
public function getDateUpdated(){
return $this->dateUpdated;
}
public function setDateUpdated($dateUpdated=NULL){
if($dateUpdated==NULL){
$this->dateUpdated = new \DateTime("now", new \DateTimeZone('Europe/London'));
}
else{
$this->dateUpdated=$dateUpdated;
}
}
public function getEcomCart(){
return $this->EcomCart;
}
public function setEcomCart(EcomCart $EcomCart){
if(is_array($EcomCart)){
foreach($EcomCart as $Join){
if(is_int($Join)){
$Join=$this->Kernel->EntityManager->getRepository($this->Kernel->Settings->ICatcher->get('php.entities-namespaces')[0].'EcomCart')->findOneById($Join);
}
if(!$this->EcomCart->contains($EcomCart)){
$this->EcomCart[] = $EcomCart;
$EcomCart->setEcomOrder($this);
}
}
}
else{
if(!$this->EcomCart->contains($EcomCart)){
$this->EcomCart[] = $EcomCart;
$EcomCart->setEcomOrder($this);
}
}
}
public function RemoveEcomCart(EcomCart $EcomCart){
if($this->EcomCart->contains($EcomCart)){
$this->EcomCart->removeElement($EcomCart);
$EcomCart->RemoveEcomOrder($this);
}
}
public function clearEcomCart(){
$this->EcomCart->clear();
}
/** @PrePersist */
public function preCreate(){
$this->setDateCreated();
}
/** @preUpdate */
public function preUpdate(){
$this->setDateUpdated();
}
/** @preRemove */
public function preRemove(){
}
}
BOTH 实体的SAME 代码在localhost(XAMPP,PHP7.1,Windows)上没有任何错误。问题出在活动主机上(PHP7.1,Linux)。
答案 0 :(得分:0)
通过将此行添加到Doctrine的配置中来解决问题:
$config->setAutoGenerateProxyClasses(TRUE);
但是为什么没有它在localhost上工作仍然是一个谜。