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.

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()


1.5k
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();