How do you add abstract class library in the Codeigniter framework?

前端 未结 5 621
天命终不由人
天命终不由人 2020-12-31 20:27

I have the following code in file called AbstractClass.php in the libraries folder

abstract class AbstractClass {
  abstract prote         


        
5条回答
  •  独厮守ぢ
    2020-12-31 21:08

    I have found a simple way to use an abstract classes in Codeigniter. Just follow these steps. Go to libraries in system folder

    1. Create an abstract class and dont link it with CI just name it with simple word without CI_
    2. Create an another class name it with the same word as you give name to your file. As shown in code below
    3. Extend that class with abstract class.
    4. Then call abstract class function through your CI_class.

    System -> libraries -> lib.php

        abstract class B
        {
    
           public function lib1()
           {
               echo "This is library 1";
           }
    
           public function lib2()
           {
               echo "This is library 1";
           }
       }
    
       class CI_lib extends B
       {
           public function libs(){
            $this->lib1();
           }
       }
    

    Then call that lib from Controller.

提交回复
热议问题