我在我創建了排序的2個個子模塊,我一直在努力實現的情況下被發現使用學說被映射他們如我有一個結構如下:目標實體不能使用ZF2
我有命名1 2個模塊)帳戶 2)公司
下公司我有2個命名爲)公司 b子模塊)貨幣,同樣都具有單獨的控制器和實體。我有一個名爲公司下的憑證的實體。現在問題來了當我嘗試將Account與名爲Company's Entity Currency的子模塊進行映射時,出現此錯誤。
[Doctrine\ORM\Mapping\MappingException]
The target-entity Currency\Entity\Currency cannot be found in 'Account\Enti
ty\Voucher#currency'.
這裏是我的實體類
**Voucher Entity**
<?php
namespace Account\Entity;
use Doctrine\ORM\Mapping as ORM;
use Zend\Form\Annotation;
/**
* A Main Voucher entity.
*
* @ORM\Entity
* @ORM\Table(name="vouchers")
*
* @property int $id
* @property date $voucher_date
* @property int $voucher_number
*
* @Annotation\Name("Voucher")
*/
class Voucher {
/**
* @ORM\Id
* @ORM\Column(type="integer");
* @ORM\GeneratedValue(strategy="AUTO")
*
* @Annotation\Required(false)
*/
protected $id;
/**
* @ORM\Column(type="integer")
*
* @Annotation\Required(false)
*/
protected $voucher_number;
/**
* @ORM\ManyToOne(targetEntity="VoucherType", inversedBy="vouchers")
*/
protected $voucher_type;
/**
* @ORM\ManyToOne(targetEntity="Currency\Entity\Currency", inversedBy="vouchers")
*/
protected $currency;
/*
* Constructor
*/
public function __construct() {
$now = new \DateTime("now");
}
/**
* Magic getter to retrieve protected properties.
*
* @param string $property
*/
public function __get($property) {
if ($property == 'name') {
return $this->name();
} else {
return $this->$property;
}
}
/**
* Magic setter to save protected properties.
*
* @param string $property
* @param mixed $value
*/
public function __set($property, $value) {
$this->$property = $value;
}
public function getArrayCopy() {
}
public function exchangeArray($data) {
$this->id = (isset($data['id'])) ? $data['id'] : null;
$this->voucher_date = (isset($data['voucher_date'])) ? $data['voucher_date'] : null;
$this->voucher_number = (isset($data['voucher_number'])) ? $data['voucher_number'] : null;
}
public function populate($data) {
$this->id = isset($data['id']) ? $data['id'] : $this->id;
$this->voucher_date = isset($data['voucher_date']) ? $data['voucher_date'] : $this->category_name;
$this->voucher_number = isset($data['voucher_number']) ? $data['voucher_number'] : $this->voucher_number;
}
}
這裏是正在公司模塊的貨幣實體
<?php
namespace Company\Currency\Entity;
use Doctrine\ORM\Mapping as ORM;
use Zend\Form\Annotation;
/**
* A Main Voucher entity.
*
* @ORM\Entity
* @ORM\Table(name="currencies")
*
* @property int $id
* @property string $name
* @property string $code
*
* @Annotation\Name("Currency")
*/
class Currency {
/**
* @ORM\id
* @ORM\GeneratedValue(strategy="AUTO")
* @ORM\Column(type="integer")
*/
protected $id;
/** @ORM\Column(type="string")
*/
protected $name;
/** @ORM\Column(type="string")
*/
protected $code;
/**
* @ORM\OneToMany(targetEntity="Account\Entity\Voucher", mappedBy="currency", orphanRemoval=true)
*
* @Annotation\Required(false)
*/
protected $vouchers;
/**
* Magic getter to retrieve protected properties.
*
* @param string $property
*/
public function __get($property) {
if ($property == 'name') {
return $this->name();
} else {
return $this->$property;
}
}
/**
* Magic setter to save protected properties.
*
* @param string $property
* @param mixed $value
*/
public function __set($property, $value) {
$this->$property = $value;
}
public function getArrayCopy() {
}
public function exchangeArray($data) {
$this->id = (isset($data['id'])) ? $data['id'] : null;
$this->name = (isset($data['name'])) ? $data['name'] : null;
$this->code = (isset($data['code'])) ? $data['code'] : null;
}
public function populate($data) {
$this->id = isset($data['id']) ? $data['id'] : $this->id;
$this->name = isset($data['name']) ? $data['name'] : $this->name;
$this->code = isset($data['code']) ? $data['code'] : $this->code;
}
}
Module.Config.php
<?php
namespace Company;
return array(
'controllers' => array(
'invokables' => array(
'Company\Controller\Company' => 'Company\Controller\CompanyController',
),
),
'router' => array(
'routes' => array(
'company' => array(
'type' => 'segment',
'options' => array(
'route' => '/company[/][:action][/:id]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
),
'defaults' => array(
'controller' => 'Company\Controller\Company',
'action' => 'index',
),
),
),
),
),
// --------- Doctrine Settings For the Module
'doctrine' => array(
'driver' => array(
__NAMESPACE__ . '_driver' => array(
'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
'cache' => 'array',
'paths' => array(__DIR__ . '/../src/' . __NAMESPACE__ . '/Entity')
),
'orm_default' => array(
'drivers' => array(
__NAMESPACE__ . '\Entity' => __NAMESPACE__ . '_driver'
)
)
)
),
'view_manager' => array(
'template_path_stack' => array(
'company' => __DIR__ . '/../view',
),
),
);
糾正我,如果我錯了。從我得到的問題是,當我有一個父模塊下2個子模塊就像我的情況。我得到這個問題,如果我有點合併兩個子模塊下1個文件夾我想我不會得到這個錯誤。
我實際上練習了那個昨天,假設FQCN會有點像你說的,但問題仍然存在 –
你能說說「仍然存在問題」嗎?可能還有其他內容涉及到,但沒有更多信息就無法提供幫助。 –
好吧,我的意思是我仍然得到[Doctrine \ ORM \ Mapping \ MappingException] 在'Account \ Enti ty \ Voucher#currency'中找不到目標實體公司\貨幣\實體\貨幣。 –