Welcome Guest, Not a member yet? Register   Sign In
Inheritance methods
#1

[eluser]katama[/eluser]
Good afternoon. I am a beginner in CI. For example,i have one controller admin.php and site.php. All methods are situated there. Nowadays, i should create the same functions in admin controller and in site controller to do the same actions. And I think, this is not good. Please tell me, what varians are there to organize the structure? Thanks.
#2

[eluser]Georgi Budinov[/eluser]
I am not sure I understand exactly what you asked.
In general I would do this depending on what exactly is the purpose of these methods. Two ways:
1) Using a MY_Controller that is actually extended.
2) Creating a library that could be loaded anywhere and use its functionality.
#3

[eluser]InsiteFX[/eluser]
I would take a look at this

Base Classes Keeping it DRY

InsiteFX
#4

[eluser]katama[/eluser]
Grad Student, thanks
#5

[eluser]katama[/eluser]
I created My_Controller.php that is autoload in libraries and there are my admin.php, that must extend My_Controller.php. It looks like this.


Code:
Class Admin extends My_Controller {
function Admin() {
      parent::My_Controller();
     $this->My_Controller();
}

function index() {
   How can I inherit index() method from  My_Controller ?  
    }
}

My_Controller.php :

Code:
class My_Controller extends Controller {
  
    function My_Controller() {
        parent::Controller();
        
    $this->load->library('pagination');
        }

    function index() {
    echo "Hello from My_controller  controller";
    }
  
}
Sorry,I am a not good in OOP..Sad
And..How can I inherit index() method from My_Controller ?
Thanks
#6

[eluser]Georgi Budinov[/eluser]
As InsiteFX stated above, the link from phil's blog will help you in achieving your goal.
#7

[eluser]katama[/eluser]
Grad Student, I can't believe, that this is the one solution of problem, I tried it, but nothing helped Sad.
Maybe you can advise another solutions of such problem? Thanks
#8

[eluser]danmontgomery[/eluser]
Code:
class My_Controller extends Controller {
  
    function My_Controller() {
        parent::Controller();
        $this->load->library('pagination');
    }

    function index() {
        echo "Hello from My_controller  controller";
    }
  
}

class Admin extends My_Controller {
    function Admin() {
        parent::My_Controller();
        $this->index();
    }

}
#9

[eluser]katama[/eluser]
Lab Technician, thanks you, I forgot about $this->index().




Theme © iAndrew 2016 - Forum software by © MyBB