-
Notifications
You must be signed in to change notification settings - Fork 133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add UserModel::createNewUser()
and RegisterController
uses it
#1196
feat: add UserModel::createNewUser()
and RegisterController
uses it
#1196
Conversation
Co-authored-by: kenjis <[email protected]>
5002391
to
729af3a
Compare
729af3a
to
9bf9e7d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
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: