sfPropelFriendlyUrlBehaviorPlugin - 1.0.1

Symfony Friendly Url Plugin

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 | Show as Markdown

sfPropelFriendlyUrlBehavior plugin

This plugins allows you to automatically generate friendly url keys for your model objects based on the text contained in a column selected.

Installation

  • Install the plugin

      symfony plugin-install http://plugins.symfony-project.com/sfPropelFriendlyUrlBehavior
    
  • Enable Propel behavior support in propel.ini:

      propel.builder.AddBehaviors = true
    
  • Activate the behavior for one of your Propel models, specifying the name of the source column and/or target column. The behavior has two possible use cases. You can either store stripped title in a column you specified as target_column on the same table as your model or you can let the behavior to handle it in behavior's own table. Do not choice the second option if you have performance issues, because every time $my_obj->getFriendlyUrl() method is requested on the background the this value will be brought from this table and that will cause a couple of extra sql executions.

      sfPropelBehavior::add('Snippet', 
        array(
          'sfPropelFriendlyUrlBehavior' => array(
            'source_column' => 'title',
            'target_column' => 'stripped_title'
          )
        )
      );
    
  • There is no extra configuration, the behavior will bound a new method to the model object. In order to get the stripped text you can call getFriendlyUrl method on your model object.

      $my_model_object->getFriendlyUrl();
    
  • Unfortunately, as of PHP 5, static method calls cannot be caught by a __call(). This means that symfony behaviors are not able to add new methods to the Peer classes. This means that it is not possible to bound a static method like retrieveByFriendlyUrl to Peer class. However there is a utility class with one method retrieveByFriendlyUrl, you can use this method to retrieve your model object using it's friendly url.

      sfPropelFriendlyUrl::retrieveByFriendlyUrl('Dummy', 'my-first-blog-post');