Friday, 15 July 2011

php - One to many Relation using Doctrine in ZF2 -



php - One to many Relation using Doctrine in ZF2 -

this code

category file

<?php namespace category\entity; utilize doctrine\orm\mapping orm, zend\form\annotation; /** * category entity. * * @orm\entity * @orm\table(name="categories") * @orm\table(name="categories")) * * @property int $id * @property string $category_name * @property string $status * @property date $created_at * @property date $created_at * * @annotation\name("category") */ class category { /** * @orm\id * @orm\column(type="integer"); * @orm\generatedvalue(strategy="auto") * * @annotation\required(false) */ protected $id; /** * @orm\column(type="string") * * @annotation\attributes({"type":"text"}) * @annotation\options({"label":"category_name:"}) * @annotation\filter({"name":"stringtrim"}) * @annotation\filter({"name":"striptags"}) */ protected $category_name; /** * @orm\column(type="integer"); * @annotation\options({"label":"status:"}) * * @annotation\required(false) */ protected $status; /** * @orm\column(type="datetime") * * @annotation\required(false) */ protected $created_at; /** * @orm\column(type="datetime") * * @annotation\required(false) */ protected $updated_at; /** * @orm\onetomany(targetentity="\product\entity\product" , mappedby="category") * * */ protected $category; public function __get($property) { homecoming $this->$property; } /** * * * magic setter save protected properties. * * @param string $property * @param mixed $value */ public function __set($property, $value) { $this->$property = $value; } public function getarraycopy() { homecoming array( 'category_name' => $this->category_name, 'status' => $this->status, ); } public function exchangearray($data) { $this->id = (isset($data['id'])) ? $data['id'] : null; $this->category_name = (isset($data['category_name'])) ? $data['category_name'] : null; $this->status = (isset($data['status'])) ? $data['status'] : 0; } public function populate($data) { $this->id = isset($data['id']) ? $data['id'] : $this->id; $this->category_name = isset($data['category']) ? $data['category'] : $this->category_name; $this->status = isset($data['status']) ? $data['status'] : $this->status; } }

and here categoriesnames file

<?php namespace admin\entity; utilize doctrine\orm\mapping orm, zend\form\annotation; /** * category entity. * * @orm\entity * @orm\table(name="categories_names") * @orm\table(name="categories_names")) * * @property int $id * @property string $category * @property string $language * * @annotation\name("language") */ class categoriesnames { /** * @orm\id * @orm\column(type="integer"); * @orm\generatedvalue(strategy="auto") * * @annotation\required(false) */ protected $id; /** * * @orm\manytoone(targetentity="\category\entity\category", inversedby="category") */ private $category; /** * * @orm\manytoone(targetentity="languages", inversedby="language") */ private $language; public function __get($property) { homecoming $this->$property; } /** * * * magic setter save protected properties. * * @param string $property * @param mixed $value */ public function __set($property, $value) { $this->$property = $value; } public function getarraycopy() { homecoming array( 'category_name' => $this->category_name, 'status' => $this->status, ); } public function exchangearray($data) { $this->id = (isset($data['id'])) ? $data['id'] : null; $this->category_name = (isset($data['category'])) ? $data['category'] : null; $this->status = (isset($data['language'])) ? $data['language'] : 0; } public function populate($data) { $this->id = isset($data['id']) ? $data['id'] : $this->id; $this->category_name = isset($data['category']) ? $data['category'] : $this->category; $this->status = isset($data['language']) ? $data['language'] : $this->language; } }

and here language entity

<?php namespace admin\entity; utilize doctrine\orm\mapping orm, zend\form\annotation; /** * category entity. * * @orm\entity * @orm\table(name="languages") * @orm\table(name="languages")) * * @property int $id * @property string $language_name * @property string $language_code * * @annotation\name("language") */ class languages { /** * @orm\id * @orm\column(type="integer"); * @orm\generatedvalue(strategy="auto") * * @annotation\required(false) */ protected $id; /** * @orm\column(type="string") * * @annotation\attributes({"type":"text"}) * @annotation\options({"label":"language_name:"}) * @annotation\filter({"name":"stringtrim"}) * @annotation\filter({"name":"striptags"}) */ protected $language_name; /** * @orm\column(type="string") * * @annotation\attributes({"type":"text"}) * @annotation\options({"label":"language_code:"}) * @annotation\filter({"name":"stringtrim"}) * @annotation\filter({"name":"striptags"}) */ protected $language_code; /** * @orm\onetomany(targetentity="\admin\entity\categoriesnames" , mappedby="language") * * */ protected $language; public function __get($property) { homecoming $this->$property; } /** * * * magic setter save protected properties. * * @param string $property * @param mixed $value */ public function __set($property, $value) { $this->$property = $value; } public function getarraycopy() { homecoming array( 'category_name' => $this->category_name, 'status' => $this->status, ); } public function exchangearray($data) { $this->id = (isset($data['id'])) ? $data['id'] : null; $this->category_name = (isset($data['category_name'])) ? $data['category_name'] : null; $this->status = (isset($data['status'])) ? $data['status'] : 0; } public function populate($data) { $this->id = isset($data['id']) ? $data['id'] : $this->id; $this->category_name = isset($data['category']) ? $data['category'] : $this->category_name; $this->status = isset($data['status']) ? $data['status'] : $this->status; }

now error getting here

the target-entity admin\entity\categoriesnames cannot found in 'admin\entity\languages#language'.

with exception

/vendor/doctrine/orm/lib/doctrine/orm/mapping/mappingexception.php:428

edit: posted languages file too

php doctrine zend-framework2

No comments:

Post a Comment