• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
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.
    }

}


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.