We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Get ID (UUID_SHORT()) after create model

Hi, how get id after create model, if id = UUID_SHORT();

$page->id = new RawValue('UUID_SHORT()');
$page->create();

after create

echo $page->id; //return UUID_SHORT()


6.4k
Accepted
answer
edited Mar '14

Hi, this is my solution

create a file what extends \Phalcon\Mvc\User\Plugin;

<?php
use \Phalcon\Mvc\User\Plugin;
class Utils extends Plugin
{
    public function uuid()
    {
        $result = $this->db->query("SELECT UUID_SHORT()");
        $arr = $result->fetch();
        return $arr[0];
    }

}

in index.php

$di->set('utils',function(){
    require '../app/public/utils/Utils.php';
    $utils = new Utils();
    return $utils;
});

in controller

echo $this->utils->uuid();//95426888817704969

or model

echo $this->getDI()->getUtils()->uuid();