tourze/cms-bundle
最新稳定版本:0.0.3
Composer 安装命令:
composer require tourze/cms-bundle
包简介
CMS内容管理系统核心功能包
README 文档
README
A comprehensive CMS (Content Management System) bundle for Symfony applications, providing content management, category organization, tagging, and statistics features.
Table of Contents
- Features
- Installation
- Configuration
- Usage
- Database Schema
- Advanced Usage
- Testing
- Requirements
- Contributing
- License
Features
- Content Management: Entity-Attribute-Value (EAV) based content model
- Category System: Hierarchical content categorization
- Tag Management: Flexible tagging system with tag groups
- Search & Statistics: Content search logs and visit statistics
- Event System: Content collection, liking, and visit tracking
- JSON-RPC API: RESTful API endpoints for content operations
- Admin Interface: EasyAdmin integration for backend management
- Twig Extensions: Template helpers for CMS functionality
Installation
composer require tourze/cms-bundle
Configuration
Add the bundle to your config/bundles.php:
return [ // ... Tourze\CmsBundle\Tourze\CmsBundle::class => ['all' => true], ];
Usage
Basic Entity Structure
The bundle provides 6 core entities:
- Category: Hierarchical content categorization with tree structure
- SearchLog: Search history tracking and keyword analytics
- Tag: Content tagging system with unique tag names
- TagGroup: Organization and grouping of tags
- Topic: Content topics/articles with recommendation support
- VisitStat: Daily visit statistics tracking
Services
ContentService
Search content by keywords in EAV attributes:
use Tourze\CmsBundle\Service\ContentService; class YourController { public function __construct( private ContentService $contentService ) {} public function searchContent(string $keyword): void { $queryBuilder = $this->entityManager->createQueryBuilder(); $this->contentService->searchByKeyword($queryBuilder, $keyword); } }
StatService
Update visit statistics asynchronously:
use Tourze\CmsBundle\Service\StatService; class YourController { public function __construct( private StatService $statService ) {} public function updateStats(int $entityId): void { $this->statService->updateStat($entityId); } }
JSON-RPC Procedures
The bundle provides JSON-RPC endpoints for:
Content Operations
GetCmsEntityList: Retrieve paginated content lists with category/model filteringGetCmsEntityDetail: Get detailed content information with visit tracking
Category Management
GetCmsCategoryList: Fetch category listings by modelGetCmsCategoryDetail: Get category detailsAdminCreateCmsCategory: Create new categories (admin)AdminGetCmsCategoryList: Admin category managementAdminGetCmsCategoryTree: Hierarchical category tree structure
Events
The bundle dispatches events for content interactions:
CollectEntityEvent: When content is collected/bookmarkedLikeEntityEvent: When content is likedVisitEntityEvent: When content is visited
Twig Extensions
Use CMS functionality in templates:
{# Get single entity detail #}
{% set entity = get_cms_entity_detail(123) %}
{{ entity.title }}
{# Get entity list by model #}
{% set entities = get_cms_entity_list('article', 10, 0) %}
{% for entity in entities %}
<h2>{{ entity.title }}</h2>
{% endfor %}
Database Schema
The bundle creates the following tables:
cms_category: Hierarchical content categories with tree structureims_cms_search: Search history logs with keyword trackingcms_tag: Content tags with unique namescms_tag_group: Tag organization groupscms_topic: Content topics with recommendation supportcms_visit_stat: Daily visit statistics
Advanced Usage
Custom Entity Models
Extend the EAV model system for custom content types:
use Tourze\CmsBundle\Service\EntityService;use Tourze\CmsBundle\Service\ModelService; class CustomContentService { public function __construct( private ModelService $modelService, private EntityService $entityService ) {} public function createCustomEntity(string $modelCode, array $data): Entity { $model = $this->modelService->findValidModelByCode($modelCode); // Create and populate entity... } }
Advanced Search Integration
Implement complex search scenarios using ContentService:
use Tourze\CmsBundle\Service\ContentService; $qb = $entityRepository->createQueryBuilder('e'); $this->contentService->searchByKeyword($qb, 'search term', $model); $results = $qb->getQuery()->getResult();
Cross-Module Integration
When integrating with other modules, always use Service layer instead of direct Repository access:
// ✅ Correct - Use Service layer $entityService->findEntityBy(['id' => $id]); // ❌ Wrong - Direct Repository access violates architecture $entityRepository->findOneBy(['id' => $id]);
Testing
Run the test suite:
./vendor/bin/phpunit packages/cms-bundle/tests
Requirements
- PHP 8.1+
- Symfony 6.4+
- Doctrine ORM 3.0+
Contributing
Contributions are welcome! Please read our contributing guidelines and submit pull requests.
License
MIT License
统计信息
- 总下载量: 78
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-06-03