I can't get objects of related entity in Symfony3 - php

I use Symfony 3.2. I have two related entities:
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* #ORM\Entity(repositoryClass="AppBundle\Repository\UserRepository")
* #ORM\Table(name="user", options={"collate"="utf8mb4_unicode_ci", "charset"="utf8mb4"}, indexes={ #Index(name="idx_email", columns={"email"}) })
* #UniqueEntity(fields={"email"}, message="Пользователь с данным email'ом существует.", groups={"Registration"})
* #ORM\HasLifecycleCallbacks()
*/
class User
{
/**
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
* #ORM\Column(type="integer")
*/
private $id;
/**
*
* #ORM\OneToMany(targetEntity="AppBundle\Entity\VisitedPage", mappedBy="user")
*/
private $visitedPages;
public function __construct()
{
$this->visitedPages = new ArrayCollection();
}
public function addVisitedPage(VisitedPage $visitedPage)
{
$this->visitedPages[] = $visitedPage;
return $this;
}
/**
* Remove visitedPage
*
* #param \AppBundle\Entity\VisitedPage $visitedPage
*/
public function removeVisitedPage(\AppBundle\Entity\VisitedPage $visitedPage)
{
$this->visitedPages->removeElement($visitedPage);
}
/**
* Get visitedPages
*
* #return \Doctrine\Common\Collections\Collection
*/
public function getVisitedPages()
{
return $this->visitedPages;
}
}
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* VisitedPage
*
* #ORM\Table(name="visited_page")
* #ORM\Entity(repositoryClass="AppBundle\Repository\VisitedPageRepository")
*/
class VisitedPage
{
/**
* #var int
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var User
*
* #ORM\ManyToOne(targetEntity="AppBundle\Entity\User", inversedBy="visitedPages")
*/
private $user;
/**
* #var string
* #ORM\Column(name="page", type="text")
*/
private $page;
/**
* Get id
*
* #return int
*/
public function getId()
{
return $this->id;
}
/**
* Set user
*
* #param \AppBundle\Entity\User $user
*
* #return VisitedPage
*/
public function setUser(\AppBundle\Entity\User $user = null)
{
$this->user = $user;
return $this;
}
/**
* Get user
*
* #return \AppBundle\Entity\User
*/
public function getUser()
{
return $this->user;
}
/**
* Set page
*
* #param string $page
*
* #return VisitedPage
*/
public function setPage($page)
{
$this->page = $page;
return $this;
}
/**
* Get page
*
* #return string
*/
public function getPage()
{
return $this->page;
}
}
When i try call VisitedPage::getUser() (i mean $visitedPage->getUser()) i get object type of user.
But when i call method User::getVisitedPages() i get null.
Method User::addVisitedPage($page) works and relations are saved.
How can i decide this problem?
//Some text to pass validation

When you add Visited Page from user try this:
class User
{
//......
public function addVisitedPage(VisitedPage $visitedPage)
{
$visitedPage->setUser($this);
$this->visitedPages->add($visitedPage);
return $this;
}
}
also I think you will need to add cascade={"persist"} to your private $visitedPages; inside of User object:
/**
*
* #ORM\OneToMany(targetEntity="AppBundle\Entity\VisitedPage", mappedBy="user", cascade={"persist"})
*/
private $visitedPages;

I fixed the issue by running this command - bin/console doctrine:cache:clear-metadata

You should run
php app/console cache:clear --env=prod
or
php app/console cache:clear --env=dev
depending upon env you are working

Related

association mapping entity delete check

I have two entities with many-to-one association mapping.
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
/**
* #ORM\Table(name="ShopType")
* #ORM\Entity(repositoryClass="AppBundle\Repository\ShopTypeRepository")
*/
class ShopType
{
/**
* #ORM\Column(type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $shtId;
/**
* #ORM\Column(type="string", length=255)
*/
private $shtName;
/**
* #ORM\Column(type="integer")
*/
private $shtCreateuid;
/**
* #ORM\Column(type="DateTime")
*/
private $shtCreatedate;
/**
* #ORM\Column(type="integer")
*/
private $shtModifyuid;
/**
* #ORM\Column(type="DateTime")
*/
private $shtModifydate;
/**
* #ORM\Column(type="integer")
*/
private $shtdelete;
/**
* One Shop Type has Many Shops.
* #OneToMany(targetEntity="Shop", mappedBy="shtId")
*/
private $shids;
// ...
public function __construct() {
$this->shids = new ArrayCollection();
}
/**
* Set shtId
*
* #param string $shtId
* #return ShopType
*/
public function setShtId($shtId)
{
$this->shtId = $shtId;
return $this;
}
/**
* Get shtId
*
* #return integer
*/
public function getshtId()
{
return $this->shtId;
}
/**
* Set shtName
*
* #param string $shtName
* #return ShopType
*/
public function setShtName($shtName)
{
$this->shtName = $shtName;
return $this;
}
/**
* Get shtName
*
* #return string
*/
public function getShtName()
{
return $this->shtName;
}
/**
* Set shtCreateuid
*
* #param integer $shtCreateuid
* #return ShopType
*/
public function setShtCreateuid($shtCreateuid)
{
$this->shtCreateuid = $shtCreateuid;
return $this;
}
/**
* Get shtCreateuid
*
* #return integer
*/
public function getShtCreateuid()
{
return $this->shtCreateuid;
}
/**
* Set shtCreatedate
*
* #param \DateTime $shtCreatedate
* #return ShopType
*/
public function setShtCreatedate($shtCreatedate)
{
$this->shtCreatedate = $shtCreatedate;
return $this;
}
/**
* Get shtCreatedate
*
* #return \DateTime
*/
public function getShtCreatedate()
{
return $this->shtCreatedate;
}
/**
* Set shtModifyuid
*
* #param integer $shtModifyuid
* #return ShopType
*/
public function setShtModifyuid($shtModifyuid)
{
$this->shtModifyuid = $shtModifyuid;
return $this;
}
/**
* Get shtModifyuid
*
* #return integer
*/
public function getShtModifyuid()
{
return $this->shtModifyuid;
}
/**
* Set shtModifydate
*
* #param \DateTime $shtModifydate
* #return ShopType
*/
public function setShtModifydate($shtModifydate)
{
$this->shtModifydate = $shtModifydate;
return $this;
}
/**
* Get shtModifydate
*
* #return \DateTime
*/
public function getShtModifydate()
{
return $this->shtModifydate;
}
/**
* Set shtdelete
*
* #param string $shtdelete
* #return ShopType
*/
public function setShtDelete($shtdelete)
{
$this->shtdelete = $shtdelete;
return $this;
}
/**
* Get shtdelete
*
* #return integer
*/
public function getshtDelete()
{
return $this->shtdelete;
}
}
This is shoptype entity.
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* #ORM\Table(name="Shop")
* #ORM\Entity(repositoryClass="AppBundle\Repository\ShopRepository")
*/
class Shop
{
/**
* #ORM\Column(type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $shId;
/**
* Many Features have One Product.
* #ManyToOne(targetEntity="ShopType", inversedBy="shids")
* #JoinColumn(name="shtId", referencedColumnName="sht_id")
*/
private $shtId;
When I delete shop type, I want to check it is used in shop. How can I check? My deletion in shop type is not really delete in database, just change the sht_delete flag 0 to 1. So , I want to know shop is used specific shop type, if so, I just show message "this shop type cannot be delete.". Thanks , for your time.

Symfony and Doctrine - getDoctrine not found

I am trying to build a simple app
I have a database with a table "matches"the table structure
and i wrote this code as Entity
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* #ORM\Entity
* #ORM\Table(name="matches")
*/
class Match
{
/**
* #ORM\Column(type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #ORM\Column(type="text", length=512)
*/
private $descr;
/**
* #ORM\Column(type="string", length=255)
*/
private $team_a;
/**
* #ORM\Column(type="string", length=255)
*/
private $team_b;
/**
* #ORM\Column(type="string", length=255)
*/
private $location;
/**
* #ORM\Column(type="datetime")
*/
private $datetime;
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set descr
*
* #param string $descr
*
* #return Match
*/
public function setDescr($descr)
{
$this->descr = $descr;
return $this;
}
/**
* Get descr
*
* #return string
*/
public function getDescr()
{
return $this->descr;
}
/**
* Set teamA
*
* #param string $teamA
*
* #return Match
*/
public function setTeamA($teamA)
{
$this->team_a = $teamA;
return $this;
}
/**
* Get teamA
*
* #return string
*/
public function getTeamA()
{
return $this->team_a;
}
/**
* Set teamB
*
* #param string $teamB
*
* #return Match
*/
public function setTeamB($teamB)
{
$this->team_b = $teamB;
return $this;
}
/**
* Get teamB
*
* #return string
*/
public function getTeamB()
{
return $this->team_b;
}
/**
* Set location
*
* #param string $location
*
* #return Match
*/
public function setLocation($location)
{
$this->location = $location;
return $this;
}
/**
* Get location
*
* #return string
*/
public function getLocation()
{
return $this->location;
}
/**
* Set datetime
*
* #param \DateTime $datetime
*
* #return Match
*/
public function setDatetime($datetime)
{
$this->datetime = $datetime;
return $this;
}
/**
* Get datetime
*
* #return \DateTime
*/
public function getDatetime()
{
return $this->datetime;
}
}
and this as controller:
<?php
namespace AppBundle\Controller;
use AppBundle\Entity\Match;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpFoundation\Response;
class AddMatch
{
/**
* #Route("/addmatch")
*/
public function createAction()
{
$match = new Match();
$match->setDescr('Descrizione Partita');
$match->setTeamA('Squadra A');
$match->setTeamB('Squadra B');
$match->setLocation('a nice Gym');
$match->setLocation('12/12/2012');
$em = $this->getDoctrine()->getManager();
// tells Doctrine you want to (eventually) save the Product (no queries yet)
$em->persist($match);
// actually executes the queries (i.e. the INSERT query)
$em->flush();
return new Response('Saved new match with id '.$match->getId());
}
}
but it dosent work and I get Not Found
What am I missing?
I am super n00b :(
thanks for your help
You have to extend the base symfony controller:
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class AddMatch extends Controller
{
...
}
If, for some reason, you can't extend a controller, you still can use Doctrine entity manager. In that case you need to inject the service container and then get the entity manager with
$container->get('doctrine')->getManager();
You should thoroughly read the Symfony guide on Service Container.

Use two entities with the same name in symfony

Hi i need to use two entities with the same name but from a different bundle
Here is how i insert data in my db
use StudentsBundle\Entity\logintrys;
$em = $this->getDoctrine()->getManager();
$start = new logintrys();
$start->setStudentId($username);
$start->setLogintrys($array);
$em = $this->getDoctrine()->getManager();
$em->persist($start);
$em->flush();
And the entity class
<?php
namespace StudentsBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* logintrys
*
* #ORM\Table(name="logintrys")
* #ORM\Entity(repositoryClass="StudentsBundle\Repository\logintrysRepository")
*/
class logintrys
{
/**
* #var int
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="student_id", type="string", length=20)
*/
private $studentId;
/**
* #var array
*
* #ORM\Column(name="logintrys", type="json_array", nullable=true)
*/
private $logintrys;
/**
* Get id
*
* #return int
*/
public function getId()
{
return $this->id;
}
/**
* Set studentId
*
* #param string $studentId
*
* #return logintrys
*/
public function setStudentId($studentId)
{
$this->studentId = $studentId;
return $this;
}
/**
* Get studentId
*
* #return string
*/
public function getStudentId()
{
return $this->studentId;
}
/**
* Set logintrys
*
* #param array $logintrys
*
* #return logintrys
*/
public function setLogintrys($logintrys)
{
$this->logintrys = $logintrys;
return $this;
}
/**
* Get logintrys
*
* #return array
*/
public function getLogintrys()
{
return $this->logintrys;
}
}
My second insert query is exactly the same as the first one only now i can not use $start = new logintrys(); because this is the same name as the first
here is my entity in the teachersBundle
<?php
namespace TeachersBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* logintrys
*
* #ORM\Table(name="logintrys")
* #ORM\Entity(repositoryClass="TeachersBundle\Repository\logintrysRepository")
*/
class logintrys
{
/**
* #var int
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="docent_id", type="string", length=20)
*/
private $docentId;
/**
* #var array
*
* #ORM\Column(name="logintrys", type="json_array", nullable=true)
*/
private $logintrys;
/**
* Get id
*
* #return int
*/
public function getId()
{
return $this->id;
}
/**
* Set docentId
*
* #param string $docentId
*
* #return logintrys
*/
public function setDocentId($docentId)
{
$this->docentId = $docentId;
return $this;
}
/**
* Get docentId
*
* #return string
*/
public function getDocentId()
{
return $this->docentId;
}
/**
* Set logintrys
*
* #param array $logintrys
*
* #return logintrys
*/
public function setLogintrys($logintrys)
{
$this->logintrys = $logintrys;
return $this;
}
/**
* Get logintrys
*
* #return array
*/
public function getLogintrys()
{
return $this->logintrys;
}
}
My question is how can i use the logintrys of the StudentsBundle and TeachersBundle in the same script
Here is the error
Cannot use TeachersBundle\Entity\logintrys as logintrys because the name is already in use
Thank you in advance
When you call your entity with:
use StudentsBundle\Entity\logintrys;
you can add an 'as':
use StudentsBundle\Entity\logintrys as StudentLogintrys;
use TeachersBundle\Entity\logintrys as TeacherLogintrys;
http://php.net/manual/en/language.namespaces.importing.php
Then, in your code you can do:
$start = new StudentLogintrys();
$start2 = new TeacherLogintrys();
I think that the better way is to use inheritance in which the main class contains your logintrys member.
because in php you can't do something like that :
use StudentsBundle\Entity\logintrys;
use TeachersBundle\Entity\logintrys;
this example provide an error because script don't know that kind of class you want instantiate.
I think this is a solution (there are always better but it should work) :
class father{
private logintrys
}
class student extends father{
private id;
private studentId;
}
class teacher extends father{
private id;
private docentId;
}
to create one of them :
$start = new father();
$start->setLogintrys($array);
if($start instanceof student) $start->setStudentId($username);

Semantical Error: Class MailileoBundle\Entity\Match has no field or association named getMailid

I went through all similar issues but nothing appears to solve my problem.
I've put a simple query in my MatchRepository but it throws a semantic error.
I've double(triple) checked my entity and everything looks fine. It even works fine when I pull all Matches via findAll() and then run a $match->getMailid()
The problem appears only in the MatchRepository file.
Here's the code:
Entity:
<?php
namespace MailileoBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use MailileoBundle\Modules\DatabaseController;
use MailileoBundle\Entity\QueueItem;
use MailileoBundle\Entity\Message;
use Doctrine\Common\Collections\ArrayCollection;
/**
* #ORM\Table(name="matches")
* #ORM\Entity(repositoryClass="MailileoBundle\Entity\MatchRepository")
*/
class Match
{
/**
* #ORM\Column(type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #ORM\OneToMany(targetEntity="QueueItem", mappedBy="match")
*/
private $queueItems;
/**
* #ORM\OneToMany(targetEntity="Message", mappedBy="match")
*/
private $messages;
/**
* #ORM\Column(type="datetime")
*/
private $created;
/**
* #ORM\Column(type="string", length=15)
*/
private $mailid;
/**
* #ORM\Column(name="deleted", type="boolean")
*/
private $deleted;
/**
* Get id
*
* #return integer
*/
public function __construct($items, $mailid) {
foreach ($items as $item) {
$this->queueItems[] = $item;
}
$this->mailid = $mailid;
$this->created = new \DateTime("now");
$this->deleted = false;
}
public function getId()
{
return $this->id;
}
/**
* Set matchtwo
*
* #param string $matchtwo
*
* #return Match
*/
/**
* Set created
*
* #param \DateTime $created
*
* #return Match
*/
public function setCreated($created)
{
$this->created = $created;
return $this;
}
/**
* Get created
*
* #return \DateTime
*/
public function getCreated()
{
return $this->created;
}
/**
* Set mailid
*
* #param string $mailid
*
* #return Match
*/
public function setMailid($mailid)
{
$this->mailid = $mailid;
return $this;
}
/**
* Get mailid
*
* #return string
*/
public function getMailid()
{
return $this->mailid;
}
/**
* Set deleted
*
* #param boolean $deleted
*
* #return Match
*/
public function setDeleted($deleted)
{
$this->deleted = $deleted;
return $this;
}
/**
* Get deleted
*
* #return boolean
*/
public function getDeleted()
{
return $this->deleted;
}
/**
* Add queueItem
*
* #param \MailileoBundle\Entity\QueueItem $queueItem
*
* #return Match
*/
public function addQueueItem(\MailileoBundle\Entity\QueueItem $queueItem)
{
$this->queueItems[] = $queueItem;
return $this;
}
/**
* Remove queueItem
*
* #param \MailileoBundle\Entity\QueueItem $queueItem
*/
public function removeQueueItem(\MailileoBundle\Entity\QueueItem $queueItem)
{
$this->queueItems->removeElement($queueItem);
}
/**
* Get queueItems
*
* #return \Doctrine\Common\Collections\Collection
*/
public function getQueueItems()
{
return $this->queueItems;
}
/**
* Add message
*
* #param \MailileoBundle\Entity\Message $message
*
* #return Match
*/
public function addMessage(\MailileoBundle\Entity\Message $message)
{
$this->messages[] = $message;
return $this;
}
/**
* Remove message
*
* #param \MailileoBundle\Entity\Message $message
*/
public function removeMessage(\MailileoBundle\Entity\Message $message)
{
$this->messages->removeElement($message);
}
/**
* Get messages
*
* #return \Doctrine\Common\Collections\Collection
*/
public function getMessages()
{
return $this->messages;
}
}
Here's the repository:
<?php
namespace MailileoBundle\Entity;
/**
* MatchRepository
*
* This class was generated by the Doctrine ORM. Add your own custom
* repository methods below.
*/
class MatchRepository extends \Doctrine\ORM\EntityRepository
{
public function findMatchForMailId($mailid) {
$query = $this->getEntityManager()->createQuery("SELECT q FROM MailileoBundle:Match as q WHERE q.getMailid = :mailid")->setParameter('mailid', $mailid);
$item = $query->getOneOrNullResult();
return $item;
}
}
and I'm running this via:
$dbb = $this->container->get('doctrine.orm.entity_manager');
$match=$dbb->getRepository('MailileoBundle:Match')->findMatchForMailId($mailid);
Here's what I've tried so far:
clearing cache
updating entities/DB schema via console
restarting server
using q.mailid instead of getMailid()
I'm using symfony3.
Any advices? Thanks!!!
OK as Cerad had suggested I should use a property name not a getter.

The target-entity cannot be found in - MappingException

I have Symfony project, in which there are 2 entities - Building and Building_type. They are connected with ManyToMany uni-directional association. So, when I try to access my controller, I have this error:
The target-entity Farpost\StoreBundle\Entity\Building_type cannot be found in 'Farpost\StoreBundle\Entity\Building#building_types'.
Farpost/StoreBundle/Entity/Building.php:
namespace Farpost\StoreBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
/**
* #ORM\Entity
*
*/
class Building
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* #var string
*
* #ORM\Column(name="alias", type="string", length=255)
*/
protected $alias;
/**
* #var string
*
* #ORM\Column(name="number", type="string", length=255)
*/
protected $number;
/**
* #ORM\ManyToMany(targetEntity="Building_type")
* #ORM\JoinTable(name="buildings_types",
* joinColumns={#ORM\JoinColumn(name="building_id", referencedColumnName="id")},
* inverseJoinColumns={#ORM\JoinColumn(name="building_type_id", referencedColumnName="id")}
* )
*/
protected $building_types;
public function __construct()
{
$this->building_types = new ArrayCollection();
}
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set alias
*
* #param string $alias
* #return Building
*/
public function setAlias($alias)
{
$this->alias = $alias;
return $this;
}
/**
* Get alias
*
* #return string
*/
public function getAlias()
{
return $this->alias;
}
/**
* Set number
*
* #param string $number
* #return Building
*/
public function setNumber($number)
{
$this->number = $number;
return $this;
}
/**
* Get number
*
* #return string
*/
public function getNumber()
{
return $this->number;
}
/**
* Add building_types
*
* #param \Farpost\StoreBundle\Entity\Building_type $buildingTypes
* #return Building
*/
public function addBuildingType(\Farpost\StoreBundle\Entity\Building_type $buildingTypes)
{
$this->building_types[] = $buildingTypes;
return $this;
}
/**
* Remove building_types
*
* #param \Farpost\StoreBundle\Entity\Building_type $buildingTypes
*/
public function removeBuildingType(\Farpost\StoreBundle\Entity\Building_type $buildingTypes)
{
$this->building_types->removeElement($buildingTypes);
}
/**
* Get building_types
*
* #return \Doctrine\Common\Collections\Collection
*/
public function getBuildingTypes()
{
return $this->building_types;
}
/**
* Add buildings_types
*
* #param \Farpost\StoreBundle\Entity\Buildings_types $buildingsTypes
* #return Building
*/
public function addBuildingsType(\Farpost\StoreBundle\Entity\Buildings_types $buildingsTypes)
{
$this->buildings_types[] = $buildingsTypes;
return $this;
}
/**
* Remove buildings_types
*
* #param \Farpost\StoreBundle\Entity\Buildings_types $buildingsTypes
*/
public function removeBuildingsType(\Farpost\StoreBundle\Entity\Buildings_types $buildingsTypes)
{
$this->buildings_types->removeElement($buildingsTypes);
}
/**
* Get buildings_types
*
* #return \Doctrine\Common\Collections\Collection
*/
public function getBuildingsTypes()
{
return $this->buildings_types;
}
}
Farpost/StoreBundle/Entity/Building_type.php:
namespace Farpost\StoreBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
*
* #ORM\Entity
*
*/
class Building_type
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* #var string
*
* #ORM\Column(name="alias", type="string", length=255)
*/
protected $alias;
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set alias
*
* #param string $alias
* #return Building_type
*/
public function setAlias($alias)
{
$this->alias = $alias;
return $this;
}
/**
* Get alias
*
* #return string
*/
public function getAlias()
{
return $this->alias;
}
}
Farpost/APIBundle/Controller/DefaultController.php:
public function listAction($name)
{
$repository = $this->getDoctrine()->getManager()
->getRepository('FarpostStoreBundle:Building');
$items = $repository->findAll();
$response = new Response(json_encode($items));
$response->headers->set('Content-Type', 'application/json');
return $response;
}
Also, app/console doctrine:schema:validate output is:
[Mapping] OK - The mapping files are correct.
[Database] OK - The database schema is in sync with the mapping files.
Because the name of the entity contains an underscore _ and the PSR-0 autoloader will try to find it in Farpost/StoreBundle/Entity/Building/type.php.
You need to rename your class to BuildingType and put it in Farpost/StoreBundle/Entity/BuildingType.php
Also, make sure that your composer.json has proper entries pointing to proper namespace. Mine did not, causing this error.

Categories