Replies: 5 comments 4 replies
-
This is the basis for extending a class in PHP. use CodeIgniter\Shield\Entities\User;
...
...
class YourEntity extends User {
// Your code here
} But if your question is about how to extend the
|
Beta Was this translation helpful? Give feedback.
-
hi , this is my code : <?php
namespace App\Models\Entities;
use CodeIgniter\Entity;
use App\Models\Colori_htmlModel;
use CodeIgniter\Shield\Models\UserModel as ShieldUserModel;
use CodeIgniter\Shield\Entities\User as ShieldUserEntity;
class Users_Entity extends ShieldUserEntity
{
function colori_html()
{
$colori_html_model= new Colori_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 ?) |
Beta Was this translation helpful? Give feedback.
-
My code : <?php
declare(strict_types=1);
namespace App\Models;
use CodeIgniter\Shield\Models\UserModel as ShieldUserModel;
use App\Entity\Users_Entity;
class UserModel extends ShieldUserModel
{
protected function initialize(): 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 |
Beta Was this translation helpful? Give feedback.
-
My code : <?php
declare(strict_types=1);
namespace App\Models;
use CodeIgniter\Shield\Models\UserModel as ShieldUserModel;
use App\Entity\Users_Entity as User;
class UserModel extends ShieldUserModel
{
protected function initialize(): void
{
parent::initialize();
$this->allowedFields = [
...$this->allowedFields,
'nome',
'cognome',
'telefono',
];
$this->returnType = User::class;
}
}
public function lista_completa(){
// Get the User Provider (UserModel by default)
$users_model = auth()->getProvider();
$data=[];
$data['lista']=$users_model->findAll();
echo view('empty_view',$data);
echo view('admin/users/lista_users');
}//fine lista completa
mysqli_result::fetch_object(): Argument #1 ($class) must be a valid class name, App\Entity\Users_Entity given |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
How can I properly extend
Shield\Entities\User
class? 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.
Beta Was this translation helpful? Give feedback.
All reactions