Installation
composer require cpana/basicblogbundle:dev-master
Add to AppKernel.php:
new CPANA\BasicBlogBundle\CPANABasicBlogBundle(),
Include routing in app/config/routing.yml:
CPANABasicBlogBundle:
resource: "@CPANABasicBlogBundle/Resources/config/routing.yml"
Database Setup
php app/console cache:clear
php app/console doctrine:schema:update --force
First Admin Action
Navigate to /app_dev.php/admin/blog to create your first post (title, content, tags, and image upload).
View Results
Visit /app_dev.php/blog to see the paginated post list and individual post pages with comments.
CPANABasicBlogBundle:Admin:post route)./blog with pagination./blog/{slug}).Post Management
CPANABasicBlogBundle:Admin routes for all post operations.
Tag entity if needed (see Gotchas).Comment Handling
/blog/{slug}. Unapproved comments are hidden by default (filter via isApproved in queries)./admin/blog/comments.Pagination
KnpPaginatorBundle recommended for advanced use).config.yml if extended).Customize Templates
Override default Twig templates in app/Resources/CPANABasicBlogBundle/views/:
Post/index.html.twig (post list).Post/show.html.twig (single post + comments).Admin/post/edit.html.twig (admin form).Extend Entities
CPANA\BasicBlogBundle\Entity\Post by creating a child class and updating the mapping (e.g., add publishedAt field).
# app/config/doctrine/Post.orm.yml
CPANA\BasicBlogBundle\Entity\Post:
inheritanceType: JOINED
discriminatorColumn: { name: type, type: string }
discriminatorMap:
extended: AppBundle\Entity\ExtendedPost
userAgent) via a listener or entity extension.Routing
routing.yml:
app_blog_custom:
resource: "@AppBundle/Controller/BlogController.php"
type: annotation
prefix: /blog
Services
PostManager or CommentManager services (if available) into your controllers:
use CPANA\BasicBlogBundle\Manager\PostManager;
class MyController extends Controller {
public function __construct(PostManager $postManager) {
$this->postManager = $postManager;
}
}
Tag Handling
"laravel,symfony"). For advanced use:
Tag entity.gedmo/doctrine-extensions for ArrayCollection-based tags.Post entity and add a tags relation:
/**
* @ORM\ManyToMany(targetEntity="AppBundle\Entity\Tag")
*/
private $tags;
Image Uploads
web/uploads/blog/ by default. Security risks:
Symfony\Bridge\Doctrine\Form\Type\EntityType for file uploads with validation.liip/imagine-bundle for resizing.Pagination Limits
limit parameter to the PostRepository::getLatest() method (if exposed) or override the controller.Comment Spam
honeypot field or integrate friendsofsymfony/user-bundle for user-based comments.Doctrine Schema Updates
--force on doctrine:schema:update drops tables. Use migrations instead:
php app/console doctrine:migrations:diff
php app/console doctrine:migrations:migrate
Routing Issues
php app/console cache:clear
php app/console debug:router
Form Errors
PostType and CommentType forms in src/CPANA/BasicBlogBundle/Form/:
allow_file_upload is set for image fields.Database Queries
app/config/config_dev.yml:
doctrine:
profiling: true
php app/console debug:query to inspect generated SQL.Custom Fields
Post entity and update the form type (PostType) to include new fields (e.g., excerpt, author).Event Listeners
post.persist) to add logic:
// src/AppBundle/EventListener/PostListener.php
class PostListener {
public function onPostPersist(LifecycleEventArgs $args) {
$post = $args->getEntity();
$post->setSlug(Str::slug($post->getTitle()));
$em = $args->getEntityManager();
$em->flush();
}
}
services.yml:
services:
app.post_listener:
class: AppBundle\EventListener\PostListener
tags:
- { name: doctrine.event_listener, event: post.persist }
API Endpoints
// src/AppBundle/Controller/BlogApiController.php
class BlogApiController extends Controller {
public function getPostsAction() {
$posts = $this->getDoctrine()->getRepository('CPANABasicBlogBundle:Post')->findAll();
return new JsonResponse($posts);
}
}
Testing
$client = static::createClient();
$crawler = $client->request('GET', '/admin/blog');
$form = $crawler->selectButton('Create')->form([
'post[title]' => 'Test Post',
'post[content]' => 'Test Content',
]);
$client->submit($form);
How can I help you explore Laravel packages today?