Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Basicblogbundle Laravel Package

cpana/basicblogbundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps to First Use

  1. 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"
    
  2. Database Setup

    php app/console cache:clear
    php app/console doctrine:schema:update --force
    
  3. First Admin Action Navigate to /app_dev.php/admin/blog to create your first post (title, content, tags, and image upload).

  4. View Results Visit /app_dev.php/blog to see the paginated post list and individual post pages with comments.


First Use Case: Quick Post Creation

  • Admin Workflow:
    • Upload an image via the form (check CPANABasicBlogBundle:Admin:post route).
    • Assign tags (comma-separated in the form).
    • Publish immediately or draft for later.
  • Frontend Check:
    • Verify the post appears in /blog with pagination.
    • Test comment submission on the post detail page (/blog/{slug}).

Implementation Patterns

Core Workflows

  1. Post Management

    • CRUD via Admin Panel: Use the CPANABasicBlogBundle:Admin routes for all post operations.
      • Edit/Delete: Bulk actions via checkboxes in the admin list view.
    • Tagging System: Tags are stored as a comma-separated string in the database. Extend with a dedicated Tag entity if needed (see Gotchas).
  2. Comment Handling

    • Frontend Submission: Comments are submitted via a form on /blog/{slug}. Unapproved comments are hidden by default (filter via isApproved in queries).
    • Admin Moderation: Approve/unapprove or delete comments via /admin/blog/comments.
  3. Pagination

    • Frontend posts use Doctrine Pagination (KnpPaginatorBundle recommended for advanced use).
    • Default items per page: 10 (configurable via config.yml if extended).

Integration Tips

  1. 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).
  2. Extend Entities

    • Post Entity: Extend 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
      
    • Comment Entity: Add custom fields (e.g., userAgent) via a listener or entity extension.
  3. Routing

    • Add custom routes in routing.yml:
      app_blog_custom:
          resource: "@AppBundle/Controller/BlogController.php"
          type:     annotation
          prefix:   /blog
      
  4. Services

    • Inject the 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;
          }
      }
      

Gotchas and Tips

Pitfalls

  1. Tag Handling

    • Tags are stored as a plain string (e.g., "laravel,symfony"). For advanced use:
    • Fix: Override the Post entity and add a tags relation:
      /**
       * @ORM\ManyToMany(targetEntity="AppBundle\Entity\Tag")
       */
      private $tags;
      
  2. Image Uploads

    • Uploads are saved to web/uploads/blog/ by default. Security risks:
      • No validation for file types/sizes.
      • No automatic resizing.
    • Mitigation:
      • Use Symfony\Bridge\Doctrine\Form\Type\EntityType for file uploads with validation.
      • Integrate liip/imagine-bundle for resizing.
  3. Pagination Limits

    • Hardcoded to 10 items/page. Workaround: Pass a limit parameter to the PostRepository::getLatest() method (if exposed) or override the controller.
  4. Comment Spam

    • No built-in spam protection (e.g., Akismet, reCAPTCHA).
    • Solution: Add a honeypot field or integrate friendsofsymfony/user-bundle for user-based comments.
  5. Doctrine Schema Updates

    • Running --force on doctrine:schema:update drops tables. Use migrations instead:
      php app/console doctrine:migrations:diff
      php app/console doctrine:migrations:migrate
      

Debugging Tips

  1. Routing Issues

    • Clear cache after adding routes:
      php app/console cache:clear
      
    • Check routes with:
      php app/console debug:router
      
  2. Form Errors

    • Validate the PostType and CommentType forms in src/CPANA/BasicBlogBundle/Form/:
      • Ensure allow_file_upload is set for image fields.
      • Add custom validation constraints if needed.
  3. Database Queries

    • Enable Doctrine profiling in app/config/config_dev.yml:
      doctrine:
          profiling: true
      
    • Use php app/console debug:query to inspect generated SQL.

Extension Points

  1. Custom Fields

    • Extend the Post entity and update the form type (PostType) to include new fields (e.g., excerpt, author).
  2. Event Listeners

    • Hook into lifecycle events (e.g., 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();
          }
      }
      
    • Register in services.yml:
      services:
          app.post_listener:
              class: AppBundle\EventListener\PostListener
              tags:
                  - { name: doctrine.event_listener, event: post.persist }
      
  3. API Endpoints

    • Create a custom controller to expose posts/comments via JSON:
      // src/AppBundle/Controller/BlogApiController.php
      class BlogApiController extends Controller {
          public function getPostsAction() {
              $posts = $this->getDoctrine()->getRepository('CPANABasicBlogBundle:Post')->findAll();
              return new JsonResponse($posts);
          }
      }
      
  4. Testing

    • Use functional tests to verify routes and forms:
      $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);
      
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
comsave/common
alecsammon/php-raml-parser
chrome-php/wrench
lendable/composer-license-checker
typhoon/reflection
mesilov/moneyphp-percentage
mike42/gfx-php
bookdown/themes
aura/view
aura/html
aura/cli
povils/phpmnd
nayjest/manipulator
omnipay/tests
psr-mock/http-message-implementation
psr-mock/http-factory-implementation
psr-mock/http-client-implementation
voku/email-check
voku/urlify
rtheunissen/guzzle-log-middleware