feat: add UserModel::createNewUser() and RegisterController uses it#1196
Conversation
Co-authored-by: kenjis <kenji.uui@gmail.com>
5002391 to
729af3a
Compare
729af3a to
9bf9e7d
Compare
|
Interesting the |
What do you mean exactly? Could you clarify? |
Maybe I'm confused here or maybe I'm missing something... But I thought that:
But, in this case, when using the first approach, I'm getting a call to undefined method error: <?php
// app/Config/Auth.php
public string $userProvider = \App\Models\UserModel::class;My custom user model: <?php
declare(strict_types=1);
namespace App\Models;
use App\Entities\User;
use CodeIgniter\Shield\Models\UserModel as ShieldUserModel;
class UserModel extends ShieldUserModel
{
protected function initialize(): void
{
parent::initialize();
$this->allowedFields = [
...$this->allowedFields,
'name', // Added
];
$this->returnType = User::class;
}
}And finally our custom entity class: <?php
declare(strict_types=1);
namespace App\Entities;
use CodeIgniter\Shield\Entities\User as ShieldUser;
/**
* @property string|null $name
*/
class User extends ShieldUser
{
private ?string $name = null;
public function getName(): ?string {
return $this->name;
}
public function setName(string $name): void {
$this->name = $name;
}
}Now in any controller that extends the BaseController: <?php
// this works by calling method App\Entities\User::getName()
$name = auth()->getProvider()->findById(\user_id())->getName();
// this gives error: Call to undefined method CodeIgniter\Shield\Entities\User::getName()
$name = auth()->user()->getName();My question/concern is whether the
|
|
Please review the subject with the following changes: <?php
declare(strict_types=1);
namespace App\Models;
use App\Entities\User;
use CodeIgniter\Shield\Models\UserModel as ShieldUserModel;
class UserModel extends ShieldUserModel
{
++protected $returnType = User::class;
protected function initialize(): void
{
parent::initialize();
$this->allowedFields = [
...$this->allowedFields,
'name', // Added
];
--$this->returnType = User::class;
}
} |
|
Wow... that was tricky! Thanks @datamweb for such a prompt reply. I'm always a bit confused when methods such as |


Description
Supersedes #1172
UserModel::createNewUser()Checklist: