Welcome Guest, Not a member yet? Register   Sign In
Trait in CodeIgniter

(This post was last modified: 02-06-2023, 02:14 AM by HanogThamers.)

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->limit(10, 1);
        return $this->db->get('my_table');

class myController extends CI_Controller { 

    public function __construct(){

class ABC_Model extends CI_Model {
    use DataTablesTrait;
    function callQuery(){
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

Theme © iAndrew 2016 - Forum software by © MyBB