## A simple implementation of model behaviors for Lithium
One popular feature in other frameworks is a simple way to configure models with different classes that add functionality. Using Lithium's service location features, different class types like behaviors can be implemented easily in plugins and application code. For more details, check out `config/bootstrap.php`.
To use behaviors in your own models, you can extend `li3_behaviors\extensions\Model`, or copy `li3_behaviors\extensions\Model::__init()` to the `__init()` method of your own base model. Then, define an `$_actsAs` attribute in your model. This can be a simple array of behavior names to apply, or an associative array where the keys are behavior names, and the values are configuration arrays to be passed to the behavior classes, for example:
{{{
<?php
namespace app\models;
class Photo extends \li3_behaviors\extensions\Model {
protected $_actsAs = array(
'Locatable' => array('fields' => array('location.latitude', 'location.longitude'))
);
}
?>
}}}
To create behaviors themselves using this plugin, you must implement a method called `bind()` that accepts a fully-namespaced model class name, and an array of configuration to apply. Your behaviors must be stored in the `extensions/data/behavior` directory of your app or plugin. For example:
{{{
<?php
namespace li3_geo\extensions\data\behavior;
class Locatable extends \lithium\core\StaticObject {
protected static $_configurations = array();
public static function bind($model, array $config = array()) {
// Do your stuff with $model here, and store the result
// in static::$_configurations[$model].
}
}
?>
}}}