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

[eluser]Gabriel Labrecque[/eluser]
Quote:I think that in reality you will always need to do things to your data before you can output information. If your controller is going to output Json, you probably have to do some other stuff to that data then when you were outputting Html.

Ok, let me clarify. When my controller outputs json data, it's always because there was an Ajax call. And when there's an Ajax call, I always return an associative array of the form:
Code:
array('code' => 'ok', 'data' => $data)
or
Code:
array('code' => 'error', 'errors' => array(array('message' => 'some message here'), array('message' => 'another message here')))

My controller functions are filled with little bits of array definitions like those. If I just had this extended controller, I would save 4 lines * ~20 times.

Quote:So my guess is that the generic methods (_png, _html, _json etc) that you would put in your MY_Controller class would not have much use. Like the ‘_html’ method: what more can that method do than load a view, with the information it gets from some other function in your controller? You still need to load information, and maybe process that information before you can send it to the _html function. If that’s all done, then why not put the ‘this->load->view’ in the Controller too?

Well, right now, I'm using Smarty for a template engine. This would be a smart place to load the library. Also, there are a couple of global variables that need everywhere in the views. This would again be a smart place to load them as well.

Quote:Pretty much the same goes for the handling of post information or segment information (note: you’ll probably need both in every controller so this is not a real choice between the two). Why make these generic ‘input handling functions’? What can they do? They can take all the parts from a request and give them to another method in your Controller. That is completely unneccessary because there are already functions in CodeIgniter to get those POST variables and segment values.

Well, I personally think that writing "$this->input->post('')" for every variable looks overly verbose.

Quote:So, I get the feeling that you want to build a ‘framework in a framework’ by making all these methods that, in the end, won’t really help to DO anything. The real ‘doing’ is still going to be in the regular controller methods, supported by calls to libraries and models.

I'll sure have to evaluate the pros and cons but I don't think it's such a bad idea to build a framework within a framework.

Quote:I hope this makes sense.


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