Uh oh!
There was an error while loading. Please reload this page.
Replies: 5 comments 4 replies
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
This is the basis for extending a class in PHP. useCodeIgniter\Shield\Entities\User;
...
...
class YourEntity extends User {
// Your code here
}But if your question is about how to extend the
|
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
hi , this is my code : <?phpnamespaceApp\Models\Entities;
useCodeIgniter\Entity;
useApp\Models\Colori_htmlModel;
useCodeIgniter\Shield\Models\UserModelasShieldUserModel;
useCodeIgniter\Shield\Entities\UserasShieldUserEntity;
class Users_Entity extends ShieldUserEntity
{
functioncolori_html()
{
$colori_html_model= newColori_htmlModel();
return$colori_html_model->find($this->id_colori_html);
}
}In view : <td> <a href="#" type="button" class="btn btn-square-md ms-1" title='Colore' style="background-color:<?= $row->colori_html()->nome?> ;"> </a></td>$row come to but Call to undefined method CodeIgniter\Shield\Entities\User::colori_html() ps: wich is the way to insert code correctly (is not better insert tag code ?) |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
My code : <?phpdeclare(strict_types=1);
namespaceApp\Models;
useCodeIgniter\Shield\Models\UserModelasShieldUserModel;
useApp\Entity\Users_Entity;
class UserModel extends ShieldUserModel
{
protectedfunctioninitialize(): void
{
parent::initialize();
$this->allowedFields = [
...$this->allowedFields,
'nome',
'cognome',
'telefono',
];
$this->returnType = UserModel::class;
}
}Call to undefined method App\Models\UserModel::colori_html it seem call Model's function instead Entitie's function Furthermore $row->email return empty ... if i remove $this->returnType = UserModel::class; return correct value |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
My code : <?phpdeclare(strict_types=1);
namespaceApp\Models;
useCodeIgniter\Shield\Models\UserModelasShieldUserModel;
useApp\Entity\Users_EntityasUser;
class UserModel extends ShieldUserModel
{
protectedfunctioninitialize(): void
{
parent::initialize();
$this->allowedFields = [
...$this->allowedFields,
'nome',
'cognome',
'telefono',
];
$this->returnType = User::class;
}
}publicfunctionlista_completa(){
// Get the User Provider (UserModel by default)$users_model = auth()->getProvider();
$data=[];
$data['lista']=$users_model->findAll();
echoview('empty_view',$data);
echoview('admin/users/lista_users');
}//fine lista completamysqli_result::fetch_object(): Argument #1 ($class) must be a valid class name, App\Entity\Users_Entity given |
I've been struggling with this for two days. I am using CI 4.5.5 codeigniter4/shield 1.1.0. use CodeIgniter\Database\Exceptions\DataException;
use CodeIgniter\Entity\Cast\ObjectCast;
use CodeIgniter\Shield\Entities\User as EntitiesUser;
-use CodeIgniter\Shield\Entities\User;+use App\Entities\UserEntity as User;
use CodeIgniter\Shield\Models\DatabaseException;
use CodeIgniter\Shield\Models\UserModel as ShieldUserModel;
use Exception;
/**
* UserModel
* * Interacts with User database table
*/
final class UserModel extends ShieldUserModel
{
/**
* initialize
* * Class initialisation code, runs after __construct()
*
* @return void
*/
protected function initialize(): void
{
parent::initialize();
$this->allowedFields = [
...$this->allowedFields,
'display_name'
];
+ $this->returnType = User::class;
}But this does: use CodeIgniter\Database\Exceptions\DataException;
use CodeIgniter\Entity\Cast\ObjectCast;
use CodeIgniter\Shield\Entities\User as EntitiesUser;
-use CodeIgniter\Shield\Entities\User;+use App\Entities\UserEntity as User;
use CodeIgniter\Shield\Models\DatabaseException;
use CodeIgniter\Shield\Models\UserModel as ShieldUserModel;
use Exception;
/**
* UserModel
* * Interacts with User database table
*/
final class UserModel extends ShieldUserModel
{
+ protected $returnType = User::class;
/**
* initialize
* * Class initialisation code, runs after __construct()
*
* @return void
*/
protected function initialize(): void
{
parent::initialize();
$this->allowedFields = [
...$this->allowedFields,
'display_name'
];
- $this->returnType = User::class;
}If anyone can explain why is this so, I'd appreciate it. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
How can I properly extend
Shield\Entities\Userclass? Is there a simple approach without side effects?To be clear, I would like to add new methods for a logged in user, i.e. to the User entity, not to the UserModel. The Shield's UserModel can be extended quiet easily.
TIA.
All reactions