Welcome Guest, Not a member yet? Register   Sign In
How to split the controller / model workload
#7

[eluser]xwero[/eluser]
First of all html and js should be in the view files. This is why you are having trouble creating a graph. If you keep html out of the models and controllers you can return every formating possible in your views. If you want to make it easy on yourself you can create helpers to generate html for you.

The way i would do it is to have controller method(s) that accepts parameters and based on the controller method the model outputs the data needed to create the content of the view.
I'm not sure how complex your reports are but to make it easier on the user you could create a few report formats based on the barebones report. Lets say you have following urls for the reports users/invoices (show all invoices per user), users/products (show all products per user), invoices/user/1, products/user/1, invoices/products (show products that are attached to invoices). None of them have javascript functions. And say the javascript funtionality is sorting and filtering. Then you can add segments javascript/sort|filter. javascript/sort/filter can be shortened to javascript/all.
In your controller you check if javascript functionality needs to be added or not and you add a link to the js file that has the demanded functionality.
Code:
function invoices_users()
{
  
   if($this->uri->segment(3) == 'javascript' && $this->uri->total_segments() > 3)
   {
      $content['javascript'] = $this->load->view('jslink',array('filename'=>implode('.',array_slice($this->uri->segment_array(),4))),TRUE);
   }
}
The javascript files will be named sort.js, filter.js, all.js (joined sort and filter file)

The same thing with the parameters you can use to select the the output. the method would be
Code:
function invoices_users()
{
  
   $add_javascript = array_search('javascript',$this->uri->segments());
   if($add_javascript !== FALSE && $this->uri->total_segments() > $add_javascript+1)
   {
      $content['javascript'] = $this->load->view('jslink',array('filename'=>implode('.',array_slice($this->uri->segment_array(),$add_javascript+1))),TRUE);
   }
   $output = array_search('output',$this->uri->segments());
   if($output === FALSE  OR $this->uri->segment($output+2) === FALSE)
   {
     $this->load->view('html',$content);
   }
   else
   {
      switch($this->uri->segment($output+2))
      {
         case 'graph':
           $this->load->view('graph',$content);
           break;
      }
   }
}
Of course there should be more checks for better security but you get the idea i think.


Messages In This Thread
How to split the controller / model workload - by El Forum - 06-24-2008, 03:23 AM
How to split the controller / model workload - by El Forum - 06-24-2008, 03:38 AM
How to split the controller / model workload - by El Forum - 06-24-2008, 03:56 AM
How to split the controller / model workload - by El Forum - 06-24-2008, 04:03 AM
How to split the controller / model workload - by El Forum - 06-24-2008, 04:17 AM
How to split the controller / model workload - by El Forum - 06-24-2008, 04:39 AM
How to split the controller / model workload - by El Forum - 06-24-2008, 04:56 AM
How to split the controller / model workload - by El Forum - 06-24-2008, 05:27 AM
How to split the controller / model workload - by El Forum - 06-24-2008, 05:41 AM



Theme © iAndrew 2016 - Forum software by © MyBB