Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

How to use custom filters inside model


I created a custom filter inside my bootstrap:

use Phalcon\Filter;

$di->setShared('filter', function() {
    $filter = new Filter();

    $filter->add('commatodot', function ($value) {
        return preg_replace('/\./', ',', $value); 

    return $filter;

I'm trying to access it through the static function getDefault():

$test = Di::getDefault()->getService('filter');

But hot can I use my specific filter?

edited Jul '16

class SomeModel extends \Phalcon\Mvc\Model
    protected $column;
    public function setColumn($value)
        $value = $this->getDI()->getShared('filter')->sanitize($value, 'commatodot');
        $this->column = $value;
        return $this;