Welcome Guest, Not a member yet? Register   Sign In
is it ok to have repeated codes in controllers
#2

[eluser]CroNiX[/eluser]
You can create a base controller (MY_Controller), or base model (MY_Model) to do those, and then have each of your controllers extend those (or model). See this (extending core classes section): https://ellislab.com/codeigniter/user-gu...asses.html

You'd have something like:

Code:
class MY_Controller extends CI_Controller {
  function __construct()
  {
    parent::__construct();
  }

  public function insert($data_type, $data)
  {
    //insert $data based on $data_type (animal/hobby/jobs)
  }
  public function update($data_type, $data, $id)
  {
    //update $data based on $data_type where ID = $id
  }
}

Then you controllers would be like:
Code:
class Animal extends MY_Controller {
  function __construct()
  {
    parent::__construct();
  }

  function something()
  {
    //Use a method defined in MY_Controller
    $data = array(
      'name' => 'Cheetah',
      'location' => 'Africa'
    );
    $this->insert('animal', $data);
  }
}


Messages In This Thread
is it ok to have repeated codes in controllers - by El Forum - 09-22-2014, 12:12 AM
is it ok to have repeated codes in controllers - by El Forum - 09-22-2014, 08:50 AM
is it ok to have repeated codes in controllers - by El Forum - 09-23-2014, 11:55 AM
is it ok to have repeated codes in controllers - by El Forum - 09-24-2014, 01:56 AM
is it ok to have repeated codes in controllers - by El Forum - 09-24-2014, 04:58 AM
is it ok to have repeated codes in controllers - by El Forum - 09-24-2014, 06:44 AM
is it ok to have repeated codes in controllers - by El Forum - 09-24-2014, 09:25 AM
is it ok to have repeated codes in controllers - by El Forum - 10-01-2014, 01:57 AM
is it ok to have repeated codes in controllers - by El Forum - 10-01-2014, 02:41 AM



Theme © iAndrew 2016 - Forum software by © MyBB