CodeIgniter Forums
Myth:Auth - Printable Version

+- CodeIgniter Forums (
+-- Forum: CodeIgniter 4 (
+--- Forum: CodeIgniter 4 Addins (
+--- Thread: Myth:Auth (/showthread.php?tid=75039)

Pages: 1 2 3 4 5 6

RE: Myth:Auth - InsiteFX - 11-13-2020

I put this together tonight may help you.

PHP Code:
    // -------------------------------------------------------------------

     * getUser ()
     * -------------------------------------------------------------------
     * Usage:
     * NOTE: $id can be left blank it will then user the auth_helper
     *       user_id() method. But this only works if user is logged in.
     * $user = $this->getUser($id);
     * $user = $this->getUser();
     * echo $user->username;
     * @param  int $id
     * @return object
public function getUser(int $id 0) : object
$data = [];

// connect to the database.
$db db_connect();
$builder $db->table('users');

         * check user id if it does not exsist we assign the admin id
         * to avoid error.
if ($id == 0)
// get the logged in user
if (user_id() != null)
$id user_id();
$id 1;

// get the users record.
$query $builder->where('id'$id)

$results $query->getResult();

        foreach (
$results as $row)
$data $row;



Returns the complete user object.

10-15-2020 - Update to do better error checking on the user id.

RE: Myth:Auth - suvi - 11-13-2020

Perfect, thanks Smile

RE: Myth:Auth - InsiteFX - 11-13-2020

You can change the result to an array if you like, I like to work with objects.

RE: Myth:Auth - suvi - 11-15-2020

Almost there, one thing though...

I'm trying to create a form where administrators can create new users. It has a list of groups that can be assigned to the new user. By reading Myth's code I figured out how to create the user in my own controller and how to assign groups to user id with GroupModel. My problem is, I don't know the user id of the newly created user.

Is there some direct way to find out what the user id is?

$users = model('UserModel');
$user = new User($this->request->getPost($allowedPostFields));

// how do i get the id of the newly created $user?

RE: Myth:Auth - InsiteFX - 11-15-2020

You need to return the insert id of the new user, you could also pass it in the session.

PHP Code:

RE: Myth:Auth - suvi - 11-15-2020

Much simpler than the custom User model and entity I wrote to get around the problem Big Grin

RE: Myth:Auth - lan89 - 12-05-2020

Nice work and nice package!

I have question

How to extends user model & user entities ?. I get this error when try to load getDisplayName() function on Entities

Quote:ErrorException #1

Class 'Myth\Auth\Entities\User' not found


PHP Code:
<?php namespace App\Entities;

User extends \Myth\Auth\Entities\User
    public function 


PHP Code:
<?php namespace App\Models;

UserModel extends \Myth\Auth\Models\UserModel
$returnType 'App\Entities\User';
    protected $allowedFields = [


RE: Myth:Auth - MGatner - 12-06-2020

“ Class 'Myth\Auth\Entities\User' not found”

Sounds like you don’t have the package installed correctly. Are you able to use other portions of it?

RE: Myth:Auth - lan89 - 12-06-2020

(12-06-2020, 05:33 AM)MGatner Wrote: “ Class 'Myth\Auth\Entities\User' not found”

Sounds like you don’t have the package installed correctly. Are you able to use other portions of it?

Nevermind m8, i found this issue. I need to load function authentication on Services and all is working good. good reference for extending entities and so on . i take it from :

How to use the invitation feature? - suvi - 12-30-2020

In Config/Auth.php theres this:

PHP Code:
    // Allow Invitations
    // When enabled (default) users may invite unregistered users to
    // create an account and collaborate on a specific job. This will
    // generate a tokenized URL to send to the specified email that will
    // prompt the user to make an account.
    public $allowInvitations true

How can I generate the tokenized URL?
Didn't find anything in the docs or the source code.