I'm trying to setup symfony with doctrine, configuring doctrine is new for me.
I try to retrieve a entity from the database by using the following code in my controller:
$feedImport = $this->getDoctrine()->getRepository(MyClass::class);
But I keep getting the MappingException
error:
The class 'AppBundle\Entity\MyClass' was not found in the chain configured namespaces
I also tried to manually specify the fully qualified class name. But this didn't help.
However the way I looked to it the error message seems to suggest I need to do some additional configuring: that I need to add my entities/repositories to "The chain of configured namespaces". But I have some trouble finding this chain and how to configure it (if my assumptions are correct ofcourse)
Question #1: Is there some kind of namespace chain? If there is where can I see examples of how to configure it?
All the entity information is in my AppBundle
bundle. see the bundle structure below:
...
└── AppBundle
├── AppBundle.php
├── Controller
│ └── DefaultController.php
├── Entity
│ └── MyClass.php
├── Repository
│ └── MyClassRepository.php
└── Resources
└── config
└── doctrine
└── MyClass.orm.yml
...
I generated the entity class / repository / orm.yml files using the symfony bin\console
tool.
If i use the same console
tool to check the doctrine mapping info with:
doctrine:mapping:info
command I show me that the classes are correctly/sucessfuly mapped:
Found 1 mapped entity:
[OK] AppBundle\Entity\MyClass
About the process of generation of the models/entity configuration files.
I generated the meta data yaml files using the symfony console
tool. By running the command: doctrine:mapping:import
. After the yml files where created I used 'doctrine:generate:entities' to generate the enity classes.
I was under the impression that if the files where generated and store in a working bundle in the Entity
folder, the auto_mapping: true
would automatically take care of this mapping thingy.
Is this assumption correct? If not please tell me what is wrong.
The entity files and configuration are stored under the working bundle
AppBundle
The
AppBundle
is registered and working (the controller is doing his thing)- The command:
doctrine:mapping:info
seems to map the entities right away.
For the full code of the Entity Model:
<?php
namespace AppBundle\Entity;
/**
* MyClass
*/
class MyClass
{
/**
* @var integer
*/
private $id;
/**
* @var integer
*/
private $customerId;
/**
* @var integer
*/
private $feedId;
/**
* @var string
*/
private $contentHash;
/**
* @var string
*/
private $headerHash;
/**
* @var string
*/
private $feedName;
/**
* @var integer
*/
private $fileSize;
/**
* @var integer
*/
private $totalHeaderFields;
/**
* @var integer
*/
private $totalRecords;
/**
* @var string
*/
private $importStatus;
/**
* @var \DateTime
*/
private $datetimeCreated = 'CURRENT_TIMESTAMP';
/**
* @var \DateTime
*/
private $datetimeProcessed;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set customerId
*
* @param integer $customerId
*
* @return MyClass
*/
public function setCustomerId($customerId)
{
$this->customerId = $customerId;
return $this;
}
/**
* Get customerId
*
* @return integer
*/
public function getCustomerId()
{
return $this->customerId;
}
/**
* Set feedId
*
* @param integer $feedId
*
* @return MyClass
*/
public function setFeedId($feedId)
{
$this->feedId = $feedId;
return $this;
}
/**
* Get feedId
*
* @return integer
*/
public function getFeedId()
{
return $this->feedId;
}
/**
* Set contentHash
*
* @param string $contentHash
*
* @return MyClass
*/
public function setContentHash($contentHash)
{
$this->contentHash = $contentHash;
return $this;
}
/**
* Get contentHash
*
* @return string
*/
public function getContentHash()
{
return $this->contentHash;
}
/**
* Set headerHash
*
* @param string $headerHash
*
* @return MyClass
*/
public function setHeaderHash($headerHash)
{
$this->headerHash = $headerHash;
return $this;
}
/**
* Get headerHash
*
* @return string
*/
public function getHeaderHash()
{
return $this->headerHash;
}
/**
* Set feedName
*
* @param string $feedName
*
* @return MyClass
*/
public function setFeedName($feedName)
{
$this->feedName = $feedName;
return $this;
}
/**
* Get feedName
*
* @return string
*/
public function getFeedName()
{
return $this->feedName;
}
/**
* Set fileSize
*
* @param integer $fileSize
*
* @return MyClass
*/
public function setFileSize($fileSize)
{
$this->fileSize = $fileSize;
return $this;
}
/**
* Get fileSize
*
* @return integer
*/
public function getFileSize()
{
return $this->fileSize;
}
/**
* Set totalHeaderFields
*
* @param integer $totalHeaderFields
*
* @return MyClass
*/
public function setTotalHeaderFields($totalHeaderFields)
{
$this->totalHeaderFields = $totalHeaderFields;
return $this;
}
/**
* Get totalHeaderFields
*
* @return integer
*/
public function getTotalHeaderFields()
{
return $this->totalHeaderFields;
}
/**
* Set totalRecords
*
* @param integer $totalRecords
*
* @return MyClass
*/
public function setTotalRecords($totalRecords)
{
$this->totalRecords = $totalRecords;
return $this;
}
/**
* Get totalRecords
*
* @return integer
*/
public function getTotalRecords()
{
return $this->totalRecords;
}
/**
* Set importStatus
*
* @param string $importStatus
*
* @return MyClass
*/
public function setImportStatus($importStatus)
{
$this->importStatus = $importStatus;
return $this;
}
/**
* Get importStatus
*
* @return string
*/
public function getImportStatus()
{
return $this->importStatus;
}
/**
* Set datetimeCreated
*
* @param \DateTime $datetimeCreated
*
* @return MyClass
*/
public function setDatetimeCreated($datetimeCreated)
{
$this->datetimeCreated = $datetimeCreated;
return $this;
}
/**
* Get datetimeCreated
*
* @return \DateTime
*/
public function getDatetimeCreated()
{
return $this->datetimeCreated;
}
/**
* Set datetimeProcessed
*
* @param \DateTime $datetimeProcessed
*
* @return MyClass
*/
public function setDatetimeProcessed($datetimeProcessed)
{
$this->datetimeProcessed = $datetimeProcessed;
return $this;
}
/**
* Get datetimeProcessed
*
* @return \DateTime
*/
public function getDatetimeProcessed()
{
return $this->datetimeProcessed;
}
}
Any words of advise is appreciated!.
Entity
class andnamespace
? – Imanali MamadievMyProject/src/AppBundle/Entity/MyClass.php
` <?php namespace AppBundle\Entity; /** * MyClass / class MyClass { /* * @var integer */ private $id; ..... and more } ` – Beach ChickenEntity
class all of code – Imanali Mamadiev