Welcome Guest, Not a member yet? Register   Sign In
I need good design ideas for my controllers?
#5

[eluser]Gabriel Labrecque[/eluser]
Thanks for the reply mddd. I'll try to move some more project-specific stuff to the models folder and reusable stuff into the libraries folder.

One thing bothers me in the solution you suggested though is that you'd need to add those functions to all your controllers. I was considering extending the Controller class in such a way:

Code:
class MY_Controller extends Controller
{
  function _json($info)
  {
    $this->output->set_header('Content-type: application/x-json');
    echo json_encode($info);
  }

  function _png(????)
  {
    // some image magic done here
  }

  function _pdf(????)
  {
    // some pdf lib called here
  }

  function _html($view, $info)
  {
    $this->load->view($view, $info);
  }
}

Maybe that's what you had in mind in the first place but I guess it's good to make it all clear for whoever else read this thread.

That doesn't solve my problem for dealing with the inputs (i.e. POSTs and segments) though. In order to deal with segments, what I was considering to do is to pass uri segments as parameters to the controllers.

Code:
class Foo_controller extends MY_Controller
{
  function Foo_function($foo, $bar)
  {
    // if I call http://mywebsite.com/foo_controller/foo_function/segment3/segment4
    // ...then I get $foo == 'segment3' and $bar == 'segment4'
  }
}

For POSTs, we could have this:
Code:
class Bar_controller extends MY_Controller
{
  function Bar_function_post($POST)
  {
    // bar_function_post() gets called if something was posted
  }

  function Bar_function()
  {
    // bar_function() gets called if nothing was posted
  }
}

Any thought about this design?


Messages In This Thread
I need good design ideas for my controllers? - by El Forum - 04-20-2010, 09:57 AM
I need good design ideas for my controllers? - by El Forum - 04-20-2010, 10:32 AM
I need good design ideas for my controllers? - by El Forum - 04-20-2010, 11:08 AM
I need good design ideas for my controllers? - by El Forum - 04-20-2010, 11:28 AM
I need good design ideas for my controllers? - by El Forum - 04-22-2010, 09:03 AM
I need good design ideas for my controllers? - by El Forum - 04-22-2010, 09:45 AM
I need good design ideas for my controllers? - by El Forum - 04-22-2010, 10:20 AM



Theme © iAndrew 2016 - Forum software by © MyBB