Welcome Guest, Not a member yet? Register   Sign In
changing the table name with a variable
#1

Code:
class UserModel extends Model
{
    protected $table      = 'users';
    protected $primaryKey = 'id';


Hello, I want to change the table name with a variable, for example the id + _table name of the users coming from the session, how can I do this, thank you.
Reply
#2

maybe in principle ..along the lines .no clue if its going to work
Code:
class UserModel extends Model
{
    protected $table ;


public function setTableName($parameter)
    {
        $this->table= $parameter;
    }

controller

Code:
$handle = new UserModel();
$handle->setTableName('sometable');
$handle->someOtherModelMethod();
//maybe use a getter method
CMS CI4     I use Arch Linux by the way 




Arch Book
Reply
#3

The base model has a function setTable, we use that to set the table to a different one.
Reply
#4

Thank you
Reply
#5

It's in the Model not the BaseModel.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#6

https://codeigniter4.github.io/api/class...d_setTable
Reply




Theme © iAndrew 2016 - Forum software by © MyBB