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

Add function to Volt

Hi,

i want to add a funtion to Volt, i am using vokuro. Here is the compiler

$compiler->addFunction('authUserById', function ($resolvedArgs) {return '!empty($this->session->auth-identity)';});

And that is the function to add:

public function authUserById($id)
{
    $user = Users::findFirstById($id);
    if ($user == false) {
        throw new Exception('The user does not exist');
    }

    $this->checkUserFlags($user);

    $this->session->set('auth-identity', array(
        'id' => $user->id,
        'name' => $user->name,
        'profile' => $user->profile->name
    ));
}

i only need the ID from the logged client, thank you in advance.

Rgds

Stefan



60.0k
Accepted
answer

Find another way:

This in volt:

{{ loggedUser.id }}

This in indexAction:

    public function indexAction(){
        $this->view->setVar('loggedUser',$this->auth->getUser());
    }