gthm / rdf-bundle

一个用于简化 create.js 端点设置的 Symfony2 扩展包

安装: 101

依赖者: 0

建议者: 0

安全: 0

星标: 0

关注者: 3

分支: 0

开放问题: 0

类型:symfony-bundle

dev-master 2012-11-18 21:01 UTC

This package is not auto-updated.

Last update: 2024-09-28 14:42:24 UTC


README

一个用于简化 create.js 端点设置的 Symfony2 扩展包。

这个扩展包是一个简单的助手,用于设置简单的 create.js 后端。无需使用 createphp 或 symfony-cmf。

安装

  1. 添加到你的 composer.json 文件中

     "require": { 
         //...
         "gthm/rdf-bundle": "dev-master"
     }
    
  2. 启用扩展包

     <?php
     // app/AppKernel.php
    
     public function registerBundles()
     {
         $bundles = array(
             //...
             new Gthm\RfdBundle\GthmRdfBundle(),
         );
     }
    
  3. 包含配置

     // app/config/config.yml
    
     imports:
         // ..
         - { resource: @GthmRdfBundle/Resources/config/services.yml }
    

使用方法

  1. 将 RDF 注解添加到你的 Doctrine 实体中

     <?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;
     }
    
  2. 添加 PUT 动作

     /**
      * @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;
         }
     }
    
  3. 将 create.js 添加到你的网站中

添加 RDF 注解和 create.js JavaScript。

  1. 盈利

由于使用 create.js 进行编辑而不是编写管理区域可以节省时间,以及由于使用 RDF 注解而带来的 SEO 效果,我们的内容将非常容易被发现,没有任何问题,我们将变得非常富有 :D

待办事项

  • 添加测试
  • 改进类型处理(目前日期时间处理处于“可用”状态)
  • 基于注释简单创建 HTML 视图的命令