Bundle to manage static pages easy. It is designed using simple CQRS, DDD and Repository Pattern.
You have to add bundle to requirements in package.json
"require": {
"apsensa/page-bundle": "dev-master"
},
Next, you have to defined custom repositories
"repositories": [
{
"url": "https://[email protected]/explodus/pagebundle.git",
"type": "git"
}
]
In /app/config/routing.yml add bundle routing at the end of file beacuse of Symfony routing loading order:
page_routing:
resource: '@ApsensaPageBundle/Resources/config/routing.yml'
Import services to app services: /app/config/services.yml
imports:
- { resource: '@ApsensaPageBundle/Resources/config/services.yml' }
There is a few services to get pages, or create new one. If would like to do it in controller, do it like this:
- Get all pages count
/** @var DoctrinePageQuery $pageQuery */
$pageQuery = $this->get('pages_query');
/** @var int $count */
$count = $pageQuery->count();
- Get page view object by id
/** @var DoctrinePageQuery $pageQuery */
$pageQuery = $this->get('pages_query');
/** @var PageView $page */
$page = $pageQuery->getById($id);
- Get all pages as view objects
/** @var DoctrinePageQuery $pageQuery */
$pageQuery = $this->get('pages_query');
/** @var PageView $pages */
$pages = $pageQuery->getAll();
- Get page by slug as view object
/** @var DoctrinePageQuery $pageQuery */
$pageQuery = $this->get('pages_query');
/** @var PageView $page */
$page = $pageQuery->getBySlug($slug);
- Create new page
$newPageCommand = new CreateNewPage('mySlug', 'myTitle', 'myContent');
/** @var CreateNewPageHandler $newPageHandler */
$newPageHandler = $this->get('new_page_handler');
$newPageHandler->handle($newPageCommand);
/** @var PagesRepository $pagesRepository */
$pagesRepository = $this->get('pages_repository');
$pagesRepository->commit();