Trait in CodeIgniter |
I'm trying to use traits in CodeIgniter. I put the Trait in the libraries directory and then loaded the library in the controller. Then I used the trait in the model, but it didn't work and echatspin echatrandom I received the following error
Trait file (in library): trait DataTablesTrait{ public function query(){ $this->db->select('*'); $this->db->limit(10, 1); return $this->db->get('my_table'); } } ?> Controller: class myController extends CI_Controller { public function __construct(){ parent::__construct(); $this->load->library('DataTablesTrait'); $this->load->model('ABC_Model'); } } Model: class ABC_Model extends CI_Model { use DataTablesTrait; function callQuery(){ $this->query(); } } I got this error: Non-existent class: DataTablesTrait Please advise
You need to use namespaces correctly.
See https://www.w3schools.com/php/php_namespaces.asp |
Welcome Guest, Not a member yet? Register Sign In |