Welcome Guest, Not a member yet? Register   Sign In
How to dynamically set properties of the model?
#1

I want to set these dynamically upon initialization of the model:

Code:
<?php namespace App\Models;

use CodeIgniter\Model;

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

    protected $useAutoIncrement = true;

    protected $returnType     = 'array';
    protected $useSoftDeletes = true;

    protected $allowedFields = ['name', 'email'];

    protected $useTimestamps = false;
    protected $createdField  = 'created_at';
    protected $updatedField  = 'updated_at';
    protected $deletedField  = 'deleted_at';

    protected $validationRules    = [];
    protected $validationMessages = [];
    protected $skipValidation     = false;
}

How can I pass in these values as parameters to the model?

I'd like to do something like this:

Code:
$this->model = new MyModel($config);

But the model obviously expect a ConnectionsInterface and a ValidationInterfave upon construction ...
Reply


Messages In This Thread
How to dynamically set properties of the model? - by blaasvaer - 09-17-2020, 04:05 AM



Theme © iAndrew 2016 - Forum software by © MyBB