dev-master
9999999-devA Symfony2 Bundle for an easy setup of create.js endpoints
MIT
The Requires
- php >=5.3.0
- symfony/symfony >=2.1.0
A Symfony2 Bundle for an easy setup of create.js endpoints
A Symfony2 Bundle for an easy setup of create.js endpoints., (*1)
This Bundle is a very simple helper for setting up a simple create.js backend. No need for createphp or symfony-cmf., (*2)
Add to your composer.json, (*3)
"require": { //... "gthm/rdf-bundle": "dev-master" }
Enable Bundle, (*4)
<?php // app/AppKernel.php public function registerBundles() { $bundles = array( //... new Gthm\RfdBundle\GthmRdfBundle(), ); }
Include Config, (*5)
// app/config/config.yml imports: // .. - { resource: @GthmRdfBundle/Resources/config/services.yml }
add the RDF Annotations to your Doctrine Entities, (*6)
<?php namespace Acme\ContentBundle\Entity; use Doctrine\ORM\Mapping as ORM; use Gthm\RdfBundle\Annotations as RDF; /** * Acme\ContentBundle\Entity\Article * * @RDF\Type(name="http://schema.org/Article") * @RDF\Subject(route="content.article.update", params={"slug":"slug"}) * @ORM\Table() * @ORM\Entity(repositoryClass="Acme\ContentBundle\Entity\ArticleRepository") */ class Article { /** * @var string $title * * @RDF\Property(name="http://schema.org/headline") * @ORM\Column(name="title", type="string", length=255) */ private $title; /** * @var string $introText * * @RDF\Property(name="http://schema.org/alternativeHeadline") * @ORM\Column(name="introText", type="text") */ private $introText; /** * @var string $mainText * * @RDF\Property(name="http://schema.org/text") * @ORM\Column(name="mainText", type="text") */ private $mainText; /** * @var \DateTime $publishDate * * @RDF\Property(name="http://schema.org/datePublished") * @ORM\Column(name="publishDate", type="datetime") */ private $publishDate; }
add the PUT action, (*7)
/** * @Route("/article/{slug}", name="content.article.update") * @Method({"PUT"}) */ public function updateAction($slug) { /** @var $repo \Gthm\ContentBundle\Entity\ArticleRepository */ $repo = $this->getDoctrine()->getRepository('\Acme\ContentBundle\Entity\Article'); /** @var $news \Gthm\NewsBundle\Entity\NewsPost */ $article = $repo->findOneBySlug($slug); if(!$article instanceof \Acme\ContentBundle\Entity\Article) { throw $this->createNotFoundException('This article does not exist'); } try { /** @var $mapper \Gthm\RdfBundle\Mapper\MapperInterface */ $mapper = $this->get('gthm.rdfbundle.mapper'); $json = $this->getRequest()->getContent(); $mapper->applyRepresentation($article, $json); $manager = $this->getDoctrine()->getManagerForClass(get_class($article)); $manager->persist($article); $manager->flush(); return $mapper->getRepresentation( $article ); } catch( \Exception $e ) { echo $e->getMessage(); exit; } }
Add create.js to your site, (*8)
Add the RDF Annotation and the create.js Javascript., (*9)
Because of the timesaving effect of using create.js for editing instead of writing admin areas, and the SEO effect for the content because of the usage of the RDF Annotation our content will be found so extreamly easy that nothing can go wrong and we will become ridiculously rich :D, (*10)
A Symfony2 Bundle for an easy setup of create.js endpoints
MIT