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.

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



21.5k
Accepted
answer

Find another way:

This in volt:

{{ loggedUser.id }}

This in indexAction:

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