ed / blog-bundle
Symfony EDBlogBundle
Requires
- php: >=5.3.3
- doctrine/doctrine-fixtures-bundle: *
- incenteev/composer-parameter-handler: ~2.0
- jms/serializer-bundle: 0.13.0
- knplabs/knp-paginator-bundle: *
- sensio/framework-extra-bundle: ~3.0,>=3.0.2
- sonata-project/doctrine-orm-admin-bundle: ^2.3
- sonata-project/media-bundle: ~2.3
- stof/doctrine-extensions-bundle: ~1.1@dev
- symfony/assetic-bundle: ~2.3
- symfony/symfony: >=2.4
- twig/extensions: ~1.0
Requires (Dev)
- behat/behat: ~3.0
- behat/mink: ~1.6
- behat/mink-browserkit-driver: ~1.2
- behat/mink-extension: ~2.0
- behat/mink-goutte-driver: ~1.0
- behat/mink-selenium2-driver: ~1.1
- behat/symfony2-extension: ~2.0
- doctrine/doctrine-bundle: ~1.3
- sensio/generator-bundle: ~2.3
- swiftmailer/swiftmailer: ~4.3|~5
- symfony/validator: ~2.3
- symfony/yaml: ~2.3
- willdurand/propel-typehintable-behavior: ~1.0
This package is not auto-updated.
Last update: 2024-09-28 18:15:56 UTC
README
EDBlogBundle 是一个功能丰富且用户友好的 Symfony2 博客扩展包。它提供了许多有趣的功能,可以将您的 Symfony2 应用程序转变为一个专业的博客平台。它非常直观和灵活,您可以轻松地根据自身需求进行调整。
特性
- 博客管理面板
- 用户管理,多个角色:贡献者、作者、编辑和管理员
- 评论管理
- 分类
- 标签
- 支持多版本修订、写锁、自动保存的文章...
- 媒体库
- RSS 订阅
许可证
此扩展包遵循 MIT 许可证。
Resources/meta/LICENSE
先决条件
此扩展包依赖于一些流行的 Symfony2 扩展包提供的许多酷炫功能,例如:
- FOSUserBundle - 用于用户管理(更多信息请参见 https://github.com/FriendsOfSymfony/FOSUserBundle)
- KnpPaginatorBundle - Symfony 2 分页器(更多信息请参见 https://github.com/KnpLabs/KnpPaginatorBundle)
- StofDoctrineExtensionsBundle - DoctrineExtensions for Symfony2(更多信息请参见 https://github.com/stof/StofDoctrineExtensionsBundle)
- SonataMediaBundle - 媒体管理(更多信息请参见 https://github.com/sonata-project/SonataMediaBundle)
演示
访问演示应用程序 http://blog-demo.etonlabs.com,查看我们的扩展包集成到标准 Symfony2 应用程序中的行为。
安装
安装过程包括以下步骤
- Composer 供应商安装和激活
- 根据提供的模型创建博客相关的实体
- EDBlogBundle 配置
- SonataMediaBundle 安装和配置
- 路由配置
- Assetic 配置
- RSS 订阅配置
- 完成
步骤 1:Composer 供应商安装和激活
如果您尚未安装 composer,可以使用以下命令安装它:
$ wget https://getcomposer.org.cn/composer.phar
然后,您可以要求以下包:
$ composer require friendsofsymfony/user-bundle:"~2.0@dev" eko/feedbundle:1.2.5 ed/blog-bundle:v1.0.5
在 app/AppKernel.php
中激活新要求的扩展包,类似于以下示例:
<?php //app/AppKernel.php class AppKernel extends Kernel { public function registerBundles() { $bundles = array( // ... new FOS\UserBundle\FOSUserBundle(), new ED\BlogBundle\EDBlogBundle(), new Knp\Bundle\PaginatorBundle\KnpPaginatorBundle(), new Sonata\CoreBundle\SonataCoreBundle(), new Sonata\MediaBundle\SonataMediaBundle(), new Sonata\EasyExtendsBundle\SonataEasyExtendsBundle(), new JMS\SerializerBundle\JMSSerializerBundle(), new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle(), new Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle(), new Eko\FeedBundle\EkoFeedBundle(), //new Application\Sonata\MediaBundle\ApplicationSonataMediaBundle(), //will be generated later ); // ... } }
步骤 2:根据提供的模型创建博客相关的实体
为了能够使用 EDBlogBundle 的功能,您必须在应用程序内部某个地方实现某些实体。这将非常简单,您需要做的只是创建相关的类并扩展我们准备好的模型。
###2.1 文章实体
创建您的文章实体,类似于以下示例
<?php //src/Acme/DemoBundle/Entity/Article.php namespace Acme\Bundle\DemoBundle\Entity; use ED\BlogBundle\Interfaces\Model\ArticleInterface; use ED\BlogBundle\Model\Entity\Article as BaseArticle; use Doctrine\ORM\Mapping as ORM; /** * @ORM\Table(name="acme_demo_article") * @ORM\HasLifecycleCallbacks * @ORM\Entity(repositoryClass="ED\BlogBundle\Model\Repository\ArticleRepository") */ class Article extends BaseArticle implements ArticleInterface { }
###2.2 文章元实体
创建您的文章元实体,类似于以下示例
<?php //src/Acme/DemoBundle/Entity/ArticleMeta.php namespace Acme\Bundle\DemoBundle\Entity; use ED\BlogBundle\Interfaces\Model\ArticleMetaInterface; use ED\BlogBundle\Model\Entity\ArticleMeta as BaseArticleMeta; use Doctrine\ORM\Mapping as ORM; /** * @ORM\Table(name="acme_demo_article_meta") * @ORM\Entity() */ class ArticleMeta extends BaseArticleMeta implements ArticleMetaInterface { }
###2.3 评论实体
创建您的评论实体,类似于以下示例
<?php //src/Acme/DemoBundle/Entity/Comment.php namespace Acme\Bundle\DemoBundle\Entity; use ED\BlogBundle\Interfaces\Model\CommentInterface; use ED\BlogBundle\Model\Entity\Comment as BaseComment; use Doctrine\ORM\Mapping as ORM; /** * @ORM\Table(name="acme_demo_comment") * @ORM\HasLifecycleCallbacks * @ORM\Entity(repositoryClass="ED\BlogBundle\Model\Repository\CommentRepository") */ class Comment extends BaseComment implements CommentInterface { }
###2.4 设置实体
创建您的设置实体,类似于以下示例
<?php //src/Acme/DemoBundle/Entity/Settings.php namespace Acme\Bundle\DemoBundle\Entity; use ED\BlogBundle\Interfaces\Model\BlogSettingsInterface; use ED\BlogBundle\Model\Entity\BlogSettings as BaseSettings; use Doctrine\ORM\Mapping as ORM; /** * @ORM\Table(name="acme_demo_settings") * @ORM\Entity(repositoryClass="ED\BlogBundle\Model\Repository\BlogSettingsRepository") */ class Settings extends BaseSettings implements BlogSettingsInterface { }
###2.5 分类实体
创建您的分类实体,类似于以下示例
<?php //src/Acme/DemoBundle/Entity/Taxonomy.php namespace Acme\Bundle\DemoBundle\Entity; use ED\BlogBundle\Interfaces\Model\BlogTaxonomyInterface; use ED\BlogBundle\Model\Entity\Taxonomy as BaseTaxonomy; use Doctrine\ORM\Mapping as ORM; /** * @ORM\Table(name="acme_demo_taxonomy") * @ORM\Entity(repositoryClass="ED\BlogBundle\Model\Repository\TaxonomyRepository") */ class Taxonomy extends BaseTaxonomy implements BlogTaxonomyInterface { }
###2.6 分类关系实体
创建您的分类关系实体,类似于以下示例
<?php //src/Acme/DemoBundle/Entity/TaxonomyRelation.php namespace Acme\Bundle\DemoBundle\Entity; use ED\BlogBundle\Interfaces\Model\TaxonomyRelationInterface; use ED\BlogBundle\Model\Entity\TaxonomyRelation as BaseTaxonomyRelation; use Doctrine\ORM\Mapping as ORM; /** * @ORM\Table(name="acme_demo_taxonomy_relation") * @ORM\Entity() */ class TaxonomyRelation extends BaseTaxonomyRelation implements TaxonomyRelationInterface { }
###2.7 术语实体
创建您的术语实体,类似于以下示例
<?php //src/Acme/DemoBundle/Entity/Term.php namespace Acme\Bundle\DemoBundle\Entity; use ED\BlogBundle\Interfaces\Model\BlogTermInterface; use ED\BlogBundle\Model\Entity\Term as BaseTerm; use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; use Doctrine\ORM\Mapping as ORM; /** * @ORM\Table(name="acme_demo_term") * @ORM\Entity() * @UniqueEntity("slug") */ class Term extends BaseTerm implements BlogTermInterface { }
###2.8 用户实体
为了能够使用 EDBlogBundle,您的用户实体应实现两个接口:BlogUserInterface 和 ArticleCommenterInterface。修改您的用户实体,类似于以下示例。
注意
有关FOSUser集成,请参阅https://github.com/FriendsOfSymfony/FOSUserBundle/blob/1.2.0/Resources/doc/index.md
<?php //src/AppBundle/Entity/User namespace Acme\Bundle\DemoBundle\Entity; use ED\BlogBundle\Interfaces\Model\BlogUserInterface; use ED\BlogBundle\Interfaces\Model\ArticleCommenterInterface; use FOS\UserBundle\Model\User as BaseUser; use Doctrine\ORM\Mapping as ORM; /** * @ORM\Entity * @ORM\Table(name="user") * @ORM\Entity(repositoryClass="AppBundle\Repository\UserRepository") */ class User extends BaseUser implements BlogUserInterface, ArticleCommenterInterface { //... /** * Required by BlogUserInterface * * @ORM\Column(name="blog_display_name", type="string") */ protected $blogDisplayName; public function getBlogDisplayName() { return $this->blogDisplayName; } public function setBlogDisplayName($blogDisplayName) { $this->blogDisplayName = $blogDisplayName; return $this; } public function getCommenterDisplayName() { return $this->blogDisplayName; } }
###2.9 用户存储库
您的用户存储库类应该实现BlogUserRepositoryInterface接口。我们准备了一个起始点,即ED\BlogBundle\Model\Repository\UserRepository
。修改您的UserRepository类,使其类似于以下内容:
<?php //src/AppBundle/Repository/UserRepository namespace AppBundle\Repository; use ED\BlogBundle\Interfaces\Repository\BlogUserRepositoryInterface; use ED\BlogBundle\Model\Repository\UserRepository as BaseUserRepository; class AppUserRepository extends BaseUserRepository implements BlogUserRepositoryInterface { }
第3步:EDBlogBundle配置
现在当您的实体就绪时,您可以在app/config/config.yml
中配置EDBlogBundle。请将ed_blog
添加到配置中,同时针对先前创建的实体,以下是一个示例:
# app/config/config.yml # ... ed_blog: entities: user_model_class: AppBundle\Entity\User article_class: Acme\Bundle\DemoBundle\Entity\Article article_meta_class: Acme\Bundle\DemoBundle\Entity\ArticleMeta blog_term_class: Acme\Bundle\DemoBundle\Entity\Term blog_taxonomy_class: Acme\Bundle\DemoBundle\Entity\Taxonomy blog_taxonomy_relation_class: Acme\Bundle\DemoBundle\Entity\TaxonomyRelation blog_comment_class: Acme\Bundle\DemoBundle\Entity\Comment blog_settings_class: Acme\Bundle\DemoBundle\Entity\Settings
第4步:SonataMediaBundle安装和配置
接下来,我们将安装和配置媒体管理核心。将以下配置添加到您的config.yml中:
# app/config/config.yml sonata_media: default_context: default db_driver: doctrine_orm # or doctrine_mongodb, doctrine_phpcr contexts: default: # the default context is mandatory providers: - sonata.media.provider.dailymotion - sonata.media.provider.youtube - sonata.media.provider.image - sonata.media.provider.file formats: crop: { width: 600 , quality: 80} small: { width: 100 , quality: 70} big: { width: 500 , quality: 70} lib: { width: 350 , height: 250 , quality: 70} excerpt: { width: 780 , height: 500 , quality: 70} cdn: server: path: /uploads/media # http://media.sonata-project.org/ filesystem: local: directory: %kernel.root_dir%/../web/uploads/media create: false
要生成ApplicationSonataMediaBundle,请打开终端并运行以下代码:
$ php app/console sonata:easy-extends:generate --dest=src SonataMediaBundle
现在您可以通过在app/AppKernel.php
中添加/取消注释此行来将ApplicationSonataMediaBundle包含在内:
<?php //app/Kernel.php //... class AppKernel extends Kernel { public function registerBundles() { $bundles = array( // ... new Application\Sonata\MediaBundle\ApplicationSonataMediaBundle(), //add/uncomment ); // ... } }
最后,我们应该为媒体存储创建本地目录
$ mkdir web/uploads
$ mkdir web/uploads/media
$ sudo chmod -R 0777 web/uploads
第5步:路由配置
通过将以下代码添加到您的app/config/routing.yml
中,启用EDBlogBundle和SonataMediaBundle的路由:
# app/config/routing.yml gallery: resource: '@SonataMediaBundle/Resources/config/routing/gallery.xml' prefix: /media/gallery media: resource: '@SonataMediaBundle/Resources/config/routing/media.xml' prefix: /media ed_blog_admin_feed: path: /feed/{type} defaults: { _controller: EDBlogBundle:Backend/Feed:feed } ed_blog_frontend: resource: "@EDBlogBundle/Controller/Frontend/" type: annotation prefix: / ed_blog: resource: "@EDBlogBundle/Controller/Backend/" type: annotation prefix: /blog/admin/ fos_user: resource: "@FOSUserBundle/Resources/config/routing/all.xml"
第6步:Assetic配置
将EDBlogBundle添加到您的Assetic配置中,类似于以下内容:
# app/config/config.yml #... assetic: # ... bundles: [ EDBlogBundle ]
第7步:RSS订阅配置
为了使用RSS订阅功能,请将eko_feed
配置添加到您的app/config/config.yml
中。请根据您的应用程序更改所需的行。
# app/config/config.yml # ... eko_feed: feeds: article: title: 'My articles/posts' description: 'Latests articles' link: route_name: ed_blog_admin_feed route_params: {type: rss} # necessary if route cantains required parameters encoding: 'utf-8' author: 'Acme' # Only required for Atom feeds
注意
访问https://github.com/eko/FeedBundle了解更多关于eko/FeedBundle的信息
第8步:完成
现在您已准备好完成EDBlogBundle的安装
$ php app/console as:in --symlink
$ php app/console as:du --env=prod
$ php app/console doc:sc:update --force
在您能够访问博客管理区域之前,您应该提升一个博客管理员。为了做到这一点,您应该将两个角色分配给未来的博客管理员用户ROLE_BLOG_USER
和ROLE_BLOG_ADMIN
。您可以通过修改您的注册操作或从控制台运行以下代码轻松完成此操作:
$ php app/console fos:user:promote
注意
每个博客用户都必须分配
ROLE_BLOG_USER
角色。除了这个角色之外,根据权限级别,他们应该拥有以下之一:
- ROLE_BLOG_ADMIN - 管理员可以查看/访问/修改:文章、用户、分类、标签、评论、媒体库、设置
- ROLE_BLOG_EDITOR - 编辑者可以查看/访问:文章、评论、媒体库
- ROLE_BLOG_AUTHOR - 作者可以查看/访问:文章、媒体库,可以发布和管理他们自己的帖子
- ROLE_BLOG_CONTRIBUTOR - 贡献者可以查看/访问:文章、媒体库,可以编写和管理他们自己的帖子,但不能发布它们
现在您可以以博客管理员身份登录并访问/blog/admin/
。请首先在/blog/admin/settings/edit
上保存您的初始博客设置。
恭喜!您的EDBlogBundle已准备就绪。
请告诉我们您的想法。
享受使用EDBlogBundle,并请记住贡献!