Seems to me dialect is read after parse of query. So how put to work,
Module.php
$di['db'] = function () use ($config)
{
$eventsManager = new \Phalcon\Events\Manager();
$eventsManager->attach('db', new DbLog);
$dialect->registerCustomFunction(
'REGEXP',
function($dialect, $expression) {
$arguments = $expression['arguments'];
return sprintf(
" REGEXP(%s)",
$dialect->getSqlExpression($arguments[0])
);
}
);
$connection = new DbAdapter(array(
"host" => $config->database->host,
"username" => $config->database->username,
"password" => $config->database->password,
"dbname" => $config->database->dbname,
"charset" => $config->database->charset,
'dialectClass' => $dialect,
));
$connection->setEventsManager($eventsManager);
return $connection;
};
Error
Phalcon\Mvc\Model\Exception: Syntax error, unexpected token IDENTIFIER(REGEXP), near to '(:pattern)', when parsing: SELECT * FROM \Apps\Models\ConteudosMeta WHERE chave REGEXP(:pattern) (69)
Query:
$model->_modelsManager->executeQuery("SELECT * FROM \\Apps\\Models\\ConteudosMeta WHERE chave REGEXP(:pattern)", ['pattern' => 'as']);
StackTrace
0 Phalcon\Mvc\Model\Query->parse()
1 Phalcon\Mvc\Model\Query->execute()
2 Phalcon\Mvc\Model\Manager->executeQuery(SELECT * FROM \Apps\Models\ConteudosMeta WHERE chave REGEXP(:pattern), Array([pattern] => as))