Welcome Guest, Not a member yet? Register   Sign In
Efficient way of handling Tasks and ToDos
#1

[eluser]YellowShadow[/eluser]
In my web application I have two separate controllers. One is a Task controller and the other is a ToDo controller. Both are virtually the same thing except they get their data from different tables and the only difference between the tables is that one column is different.

What is the most efficient way of handling this without having to create multiple controllers and models that almost do the same exact thing?

Thanks!
#2

[eluser]Aken[/eluser]
I would create a single private function that does all the work, that include a single flag of which item you are using. Then two public functions, that only call the private one with the appropriate flag.
Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class App extends CI_Controller {

    public function __construct()
    {
        parent::__construct();
    }
    
    public function index()
    {
        // Something
    }
    
    public function todo()
    {
        $this->_load('todo');
    }
    
    public function tasks()
    {
        $this->_load('tasks');
    }
    
    private function _load($task)
    {
        // All your code goes here.
    }

}




Theme © iAndrew 2016 - Forum software by © MyBB