How do I load a controller into another?

1

Well, my question is how do I load a controller / method into another controller, in CodeIgniter 2.2.2

<?php if(! defined('BASEPATH')) exit('No direct script access allowed');

class Inicio extends CI_Controller {
   public function index(){
      $this->load->library('controllers/Desenvolvedor/Desenvolvedor');
   }
}
//Esse é o controlador principal.

    
asked by anonymous 25.03.2015 / 01:08

3 answers

2

By doing a search, in addition to calling by library, you can extend your child class (eg: home.php) to the parent class (eg developer.php), allowing function calls in the controller

//desenvolvedor.php
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Desenvolvedor extends CI_Controller{
    public function __construct(){
        parent::__construct()
    }
    public function meuMetodo($algo){
        echo $algo;
    }
}


//inicio.php
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Inicio extends Desenvolvedor{
    public funcion inicio(){
        $this->meuMetodo('faça algo');
    }
}
    
25.03.2015 / 10:49
1

Good friend if I get it right, this is simple to do. I figured the following situation: that you have the Controller Developer.php that stays in controllers / Developer / Developer.php so you have another controller called Frontend.php which is in controllers / Frontend / Frontend.php so you need to use Controller Developer. php within the Frontend.php controller then inside the Frontend.php controller you will load your Controller Developer.php this way:

$this->load->library('controllers/Desenvolvedor/Desenvolvedor');
    
25.03.2015 / 01:41
1

I came up to this topic with the same question. But neither of these alternatives worked in Code Igniter 3.1.6, it may have done something wrong. But I found a very simple solution that solved my problem.

redirect('/NomeController');

After an insert into the database I used to call my controller.

    
27.10.2017 / 15:38