PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, March 14, 2022

[FIXED] getting error when I try to use Drivers in CodeIgniter

 March 14, 2022     codeigniter, codeigniter-3, php     No comments   

Issue

I'm trying to create a custom driver in codeigniter, but i got error.

here is the File hierarchy:

 /libraries
    /libraries/Taker
        /libraries/Taker/Taker.php
        /libraries/Taker/drivers
            /libraries/Taker/drivers/Taker_test.php

Code in libraries/Taker/Taker.php:

   class Taker extends CI_Driver_Library  {
        function hello() {
            echo 123;
        }
    }

Code in libraries/Taker/drivers/Taker_test.php:

class Taker_test extends CI_Driver {
    function world() {
        echo 123;
    }
}

The code in the controller:

$this->load->driver('taker');
$this->taker->hello(); //work
$this->taker->test->world(); //eror here

the error i got in the controller:

Invalid driver requested: Taker_test

Any Suggestions? Thanks


Solution

The solution is that I had to use $this->valid_drivers:

class Taker extends CI_Driver_Library  {
    
    function __construct() {
          $this->valid_drivers = ['test'];
     }
    
    
    function hello() {
        echo 123;
    }
}


Answered By - roev
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing