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

Blog Bundle Laravel Package

desarrolla2/blog-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Install via Composer

    composer require desarrolla2/blog-bundle
    

    Ensure your AppKernel.php includes the bundle in the registerBundles() method:

    $bundles[] = new Desarrolla2\BlogBundle\Desarrolla2BlogBundle();
    
  2. Run Migrations The bundle includes Doctrine migrations for its entities. Run:

    php app/console doctrine:migrations:diff
    php app/console doctrine:migrations:migrate
    
  3. Configure Routes Import the bundle’s routing in app/config/routing.yml:

    desarrolla2_blog:
        resource: "@Desarrolla2BlogBundle/Resources/config/routing.yml"
        prefix:   /blog
    
  4. First Use Case: Create a Post Use the provided controller to create a post via the admin interface (if enabled) or manually via the API:

    use Desarrolla2\BlogBundle\Entity\Post;
    
    $post = new Post();
    $post->setTitle('My First Post');
    $post->setSlug('my-first-post');
    $post->setContent('Hello, world!');
    $em->persist($post);
    $em->flush();
    

Implementation Patterns

Core Workflows

  1. SEO-Friendly URLs Slugs are auto-generated from titles (e.g., My First Postmy-first-post). Override in Post entity:

    public function setTitle($title) {
        $this->title = $title;
        $this->slug = Str::slug($title); // Use Laravel's Str helper or Symfony's StringUtil
    }
    
  2. Taxonomy Management Attach categories/tags to posts via the ManyToMany relation:

    $post->addCategory($categoryEntity);
    $post->addTag($tagEntity);
    

    Fetch posts by taxonomy in controllers:

    $posts = $em->getRepository('Desarrolla2BlogBundle:Post')
        ->findByTaxonomy('category', 'technology');
    
  3. CKEditor Integration Configure CKEditor in config.yml:

    desarrolla2_blog:
        ckeditor:
            toolbar: 'Basic'
            height: '300px'
    

    Use the ckeditor Twig extension in forms:

    {{ form_widget(form.content, {'attr': {'class': 'ckeditor'}}) }}
    
  4. Image Uploads Upload images via the PostImage entity. Use the provided upload handler in controllers:

    $post->uploadImage($request->files->get('image'));
    

    Store uploads in web/uploads/blog/ (configurable in config.yml).

  5. Comments System Enable comments in config.yml:

    desarrolla2_blog:
        comments: true
    

    Fetch comments for a post:

    $comments = $post->getComments();
    

    Moderate comments via the admin interface or manually:

    $comment->setApproved(true);
    $em->flush();
    
  6. HTTP Caching Leverage Symfony’s HTTP cache for static blog pages:

    # app/config/config.yml
    framework:
        esi: { enabled: true }
        http_cache:
            enabled: true
    

Integration Tips

  • Customize Templates Override Twig templates in app/Resources/Desarrolla2BlogBundle/views/ to modify layouts (e.g., Post/show.html.twig).
  • Extend Entities Extend Post or Comment entities in your bundle to add custom fields:
     namespace AppBundle\Entity;
     use Desarrolla2\BlogBundle\Entity\Post as BasePost;
    
     class Post extends BasePost {
         /**
          * @ORM\Column(type="string", length=255, nullable=true)
          */
         private $customField;
     }
    
  • API Endpoints Use FOSRestBundle or Symfony’s Serializer to expose blog data as JSON:
     use FOS\RestBundle\Controller\Annotations\Route;
     use FOS\RestBundle\Controller\Annotations\Get;
    
     class PostController extends Controller {
         /**
          * @Route("/api/posts", name="api_posts")
          * @Get
          */
         public function getPostsAction() {
             $posts = $this->getDoctrine()->getRepository('Desarrolla2BlogBundle:Post')->findAll();
             return $this->handleView($this->view($posts, 200));
         }
     }
    

Gotchas and Tips

Common Pitfalls

  1. Symfony 2.3 Legacy

    • The bundle is designed for Symfony 2.3, which may cause compatibility issues with newer Laravel/Symfony versions. Test thoroughly with:
      • Doctrine ORM v2.3.
      • Twig v1.16.
      • Symfony’s legacy components (e.g., SecurityBundle).
    • Workaround: Use a compatibility layer like symfony/symfony v2.3 or isolate the bundle in a subdirectory.
  2. Missing Laravel-Specific Features

    • The bundle lacks Laravel-specific integrations (e.g., Eloquent, Blade, Laravel Mix). Manually bridge gaps:
      • Replace Doctrine repositories with Eloquent models.
      • Use Laravel’s Storage facade for file uploads:
        use Illuminate\Support\Facades\Storage;
        Storage::disk('public')->put('blog/' . $filename, $file->getContent());
        
    • Tip: Create a Laravel wrapper class for the bundle’s services to abstract Symfony dependencies.
  3. CKEditor Configuration

    • The default CKEditor config may not work with modern setups. Update config.yml:
      desarrolla2_blog:
          ckeditor:
              config:
                  extraPlugins: 'image2,widget'
                  filebrowserImageBrowseUrl: '/ckfinder/browse.php?type=Images'
      
    • Ensure CKFinder is installed and configured for image uploads.
  4. Taxonomy Performance

    • Fetching posts with taxonomy filters can be slow. Optimize with:
      // Use DQL for complex queries
      $query = $em->createQuery('
          SELECT p FROM Desarrolla2BlogBundle:Post p
          JOIN p.categories c WHERE c.name = :category
      ');
      $query->setParameter('category', 'technology');
      $posts = $query->getResult();
      
  5. Image Upload Paths

    • Hardcoded upload paths (e.g., web/uploads/blog/) may conflict with Laravel’s storage. Override in config.yml:
      desarrolla2_blog:
          upload_dir: '%kernel.root_dir%/../storage/app/public/blog'
      
    • Ensure the directory is writable and symlinked to public/storage:
      php artisan storage:link
      
  6. HTTP Cache Conflicts

    • Symfony’s HTTP cache may interfere with Laravel’s caching. Disable one or the other:
      # Disable Symfony HTTP cache if using Laravel's cache
      framework:
          http_cache: { enabled: false }
      

Debugging Tips

  1. Doctrine Events Listen for postPersist/postUpdate to debug entity changes:

    $em->getEventManager()->addEventListener(
        \Doctrine\ORM\Events::postPersist,
        function ($event) {
            $post = $event->getObject();
            if ($post instanceof \Desarrolla2\BlogBundle\Entity\Post) {
                \Log::debug('Post saved:', [$post->getTitle(), $post->getSlug()]);
            }
        }
    );
    
  2. Twig Debugging Enable Twig debugging in config.yml:

    twig:
        debug: true
        strict_variables: true
    

    Check for template errors in var/log/dev.log.

  3. Route Conflicts Ensure the bundle’s routes don’t clash with Laravel’s. Use route prefixes:

    desarrolla2_blog:
        resource: "@Desarrolla2BlogBundle/Resources/config/routing.yml"
        prefix: /legacy_blog
    

Extension Points

  1. Custom Post Types Extend the Post entity to support custom content types (e.g., "Newsletter" vs. "Article"):

    class Post extends BasePost {
        /**
         * @ORM\Column(type="string", length=50)
         */
        private $type;
    
        public function setType($type) {
            $this->type = $type;
        }
    }
    

    Filter posts by type in repositories:

    $newsletters = $em->getRepository('AppBundle:Post')
        ->findBy(['type' => 'newsletter']);
    
  2. Webhooks for Comments Trigger external actions (e.g., Slack notifications) when comments are posted:

    $em->get
    
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