Welcome Guest, Not a member yet? Register   Sign In
What is the best way to write organize your code?
#2

[eluser]gtech[/eluser]
I wouldnt stress to much as CI is quite a loose frame work,

To answer your initial question:

I would be inclined to use the controller to parse the information comming in and then pass any data to the model function(s) then when the data is returned from the model you can pass that data to a single view and display accordingly (I am assuming you are developing a non Javascript/ajax orientated site). You may want to use more than one view if you have common views you wish to use for example a header or footer html.

Here are some tips I can think of:

1) Be consistant, If you find an approach that suits you that is fine, think about code readability, maintenance and reusability.

2) I consider controller functions to act like glue, they pull the data out from the request, call the correct models and then load the correct views.

3) If you have a controller function that is needed to be used in other controllers create a base controller with the common function(s) and then extend from the base controller.

4) Normally you would load a view from the controller, it is also common to load a view within a view if it makes sense to, loading a view in a model works but is a tad unauthodox.

5) Libraries and Helpers can be used in the view, controller or the model.. if you autoload a library or a helper it is automatically available in the view, model and controllers.

6) You usually would call model/models from the controller, however you can call a model from a view as long as you do not alter the data in the model/database. This would be useful if multiple controllers need to call the same view and access the same model as you would not need to load the model in every function.. however I think going down the extend controller route is a much more structured approach.

7) You can call a model in a model, but again the best way is to create a base model with common functionality and then extend it.

8) Try and keep html content away from the controller, and definatly the model.

9) Use active record to make your code database independant.

10) If you are writing code with a large datamodel, make sure you think the datamodel through first then the code structure will be more obvious.

these are things I can immediatly think of.. hope it helps


Messages In This Thread
What is the best way to write organize your code? - by El Forum - 06-19-2009, 10:00 AM
What is the best way to write organize your code? - by El Forum - 06-19-2009, 11:31 AM
What is the best way to write organize your code? - by El Forum - 06-19-2009, 11:48 AM
What is the best way to write organize your code? - by El Forum - 06-19-2009, 11:52 AM
What is the best way to write organize your code? - by El Forum - 06-19-2009, 12:12 PM
What is the best way to write organize your code? - by El Forum - 06-19-2009, 12:24 PM
What is the best way to write organize your code? - by El Forum - 06-19-2009, 12:26 PM
What is the best way to write organize your code? - by El Forum - 06-19-2009, 03:10 PM
What is the best way to write organize your code? - by El Forum - 06-19-2009, 03:52 PM
What is the best way to write organize your code? - by El Forum - 06-19-2009, 03:57 PM



Theme © iAndrew 2016 - Forum software by © MyBB