dev-master
9999999-dev https://github.com/softfly/GeneratorBundleGenerator auxiliary codes: REST from Doctrine
MIT
The Requires
- php >=5.3.9
- nikic/php-parser ^2.0
rest generator doctrine
Wallogit.com
2017 © Pedro Peláez
Generator auxiliary codes: REST from Doctrine
composer require softfly/generator-bundle, (*1)
Doctrine to REST, (*2)
Generate REST on FOSRestBundle based on Doctrine entity., (*3)
namespace AppBundle\Controller\Rest\Properties;
use FOS\RestBundle\Controller\Annotations\RouteResource;
use FOS\RestBundle\Controller\FOSRestController;
class PropertyRest extends FOSRestController
{
public function getPropertiesAction()
{
$data = array();
/* @var $propertiesRepo \Doctrine\ORM\EntityRepository */
$propertiesRepo = $this->getDoctrine()->getRepository('\\AppBundle\\Entity\\Properties\\Property');
$properties = $propertiesRepo->findAll();
/* @var $property \AppBundle\Entity\Properties\Property*/
foreach ($properties as $property) {
$row = array();
$row['id'] = $property->getId();
$row['name'] = $property->getName();
$row['slug'] = $property->getSlug();
$row['location'] = $property->getLocation();
$row['short_description'] = $property->getShortDescription();
$row['long_description'] = $property->getLongDescription();
/* @var $price \AppBundle\Entity\Offers\Price*/
foreach ($property->getPrices() as $price) {
$row1 = array();
$row1['id'] = $price->getId();
$row1['price'] = $price->getPrice();
$row['price'][] = $row1;
/* @var $timeUnit \AppBundle\Entity\Offers\TimeUnit*/
$timeUnit = $price->getTimeUnit();
if ($timeUnit) {
$row2 = array();
$row2['id'] = $timeUnit->getId();
$row2['noun'] = $timeUnit->getNoun();
$row2['adverb'] = $timeUnit->getAdverb();
$row['timeUnit'] = $row2;
}
}
$data[] = $row;
}
$view = $this->view($data, 200);
return $this->handleView($view);
}
}
Generator auxiliary codes: REST from Doctrine
MIT
rest generator doctrine