sfOrmBreadcrumbsPlugin - 1.0.3

Plugin for breadcrumbs functionality

You are currently browsing
the website for symfony 1

Visit the Symfony2 website


« Back to the Plugins Home

Signin


Forgot your password?
Create an account

Tools

Stats

advanced search
Information Readme Releases Changelog Contribute
Show source

sfOrmBreadcrumbs plugin (for symfony 1.3/1.4)

The sfOrmBreadcrumbsPlugin is a symfony plugin that provides easy breadcrumbs integration and configuration for your project application.

It consists of two modules, one for projects using Propel and the other one for projects using Doctrine.

Installation

  • Download the package and place it in your project root.

  • Install the plugin

    symfony plugin:install sfOrmBreadcrumbsPlugin-1.0.2.tgz
    
  • Activate the plugin in the config/ProjectConfiguration.class.php

    class ProjectConfiguration extends sfProjectConfiguration
    {
      public function setup()
      {
        $this->enablePlugins(array(
          '...',
          'sfOrmBreadcrumbsPlugin',
          '...'
        ));
      }
    }
  • Enable the module for your orm in your settings.yml

    • For Propel

      all:
        .settings:
          enabled_modules:      [default, sfPropelBreadcrumbs]
      
    • For Doctrine

      all:
        .settings:
          enabled_modules:      [default, sfDoctrineBreadcrumbs]
      
  • Add the component to the template you want the breadcrumbs to show in:

    • For Propel

      include_component('sfPropelBreadcrumbs', 'breadcrumbs');
    • For Doctrine

      include_component('sfDoctrineBreadcrumbs', 'breadcrumbs');
  • Clear you cache

    symfony cc
    

Breadcrumbs configuration

The plugin parses breadcrumbs configuration from a breadcrumbs.yml in your application config folder.

  • Copy breadcrumbs.yml sample

    cp plugins/sfOrmBreadcrumbsPlugin/config/breadcrumbs.yml.sample app/<application_name>/config/breadcrumbs.yml
    
  • Here's the Doctrine sample, I will deeply explain how it works:

    sf_orm_breadcrumbs:
      main:
        index:
          - { name: Home, route: homepage }
      blog:
        index:
          - { name: Blog, route: blog }
        showPost:
          - { name: Blog, route: blog }
          - { name: %title%, route: post_show, doctrine: true }
        permalink:
          - { name: 'Archive' }
          - { name: %Post%, route: post_show, doctrine: true, subobject: Post }
    
  • Place the breadcrumbs config root element first in your file:

    sf_orm_breadcrumbs:
    
  • The configuration tree follows the module/action logic. In this example I have two modules, main and blog, but you can add all the modules you need the breadcrumbs for:

    sf_orm_breadcrumbs:
      main:
        ...
      blog:
        ...
    
  • Let's take a look at blog module. I provided breadcrumbs for three actions, index, showPost and permalink.

    • index has the simplest configuration. It tells the plugin to show just one breadcrumb with name "Blog" and linked to the route "blog", which is a sfRoute object.

      blog:
        index:
          - { name: 'Blog', route: blog }
      
    • showPost is a little more complex. It consists of two breadcrumbs; the first is identical to the index one, but the second tells the plugin to show a breadcrumb for a sfDoctrineRoute object. You can set this by adding the doctrine parameter to the breadcrumb element. More, you can set the name of the breadcrumb by taking a property from the model object the route is bound to.

      Example: if I have this routing rule...

      post_show:
        url:   /blog/post/:date_slug/:slug.:sf_format
        class: sfDoctrineRoute
        options: { model: Post, type: object }
        param: { module: blog, action: showPost, sf_format: html }
        requirements:
          slug: '[\w-]+'
          sf_method: [get]
      

      ...and I can write this...

      $post = new Post();
      $post->setTitle('My title');
      echo $post->getTitle();  // 'My title'

      ...then I can set as name of my breadcrumb the "title" property of my Post object, by putting it within percent signs:

      - { name: %title%, route: post_show, doctrine: true }
      
    • What if you are in a sfDoctrineRoute rule action and you want to point your breadcrumb to a rule for another model object? Let's take a look at the second permalink breadcrumb:

      - { name: %Post%, route: post_show, doctrine: true, subobject: Post }
      

      Now, my current routing rule is this one:

      post_permalink:
        url:   /archive/:year/:month/:day/:slug.:sf_format
        class: sfDoctrineRoute
        options: { model: Permalink, type: object }
        param: { module: blog, action: permalink, sf_format: html }
        requirements:
          sf_method: [get]
      

      My route object is a Permalink object, but if I can write this...

      $permalink = new Permalink();
      $permalink->getPost(); //fetch original post

      ...then I can tell the plugin to create a breadcrumb that takes a subobject (a Post) via class method from my rule object (the Permalink) and link it to a sfDoctrineRoute suitable for the subobject.

Optional configuration

The following parameters are not mandatory, they just tweak some stuff for a better customization of your breadcrumbs.

  • Root breadcrumb. You can specify a breadcrumb to always show before the context ones. This breadcrumb work in the exact same way as the others, but it can't be used for model bound routing rules. You can make a simple text appear before the other breadcrumbs this way:

    sf_orm_breadcrumbs:
      _root: { name: My site }
    

    or you can even decide to point your root breadcrumb to your homepage, like this:

    sf_orm_breadcrumbs:
      _root: { name: Homepage, route: homepage }
    
  • Custom separator. The default separator character for the breadcrumb is '>'. To set a custom character:

    sf_orm_breadcrumbs:
      _separator: '&raquo;'
    
  • Lost text. If your configuration do not provide breadcrumbs for an action you are in, this text is displayed instead. Default text is 'somewhere'. To set a custom text:

    sf_orm_breadcrumbs:
      _lost: 'somewhere...'