CodeIgniter Forums
Need tips about large CI app - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Need tips about large CI app (/showthread.php?tid=4613)

Pages: 1 2


Need tips about large CI app - El Forum - 12-06-2007

[eluser]rogierb[/eluser]
Hi All,

At the moment I'm very happy about CI. But I could use some tips about handling larger applications. We now have over 20 controllers, a few of them have over 4000 lines of code.
There are at least about 20 models (which should actually be more then 50, but well, made some stupid choices...) And we have about 150 views, or even more I think. At the moment there are 10 different roles build in, at least as many to go.

We're about 30% done in the project. And it performs like a rocket!

What are your experiences on larger applications, when do you decide on a new controller or a new model. How do you keep oversight?

Any and all comments are more then welcome!

Cheers,
Rogier


Need tips about large CI app - El Forum - 12-06-2007

[eluser]MASS MASS[/eluser]
hi....ROGIERB

Post few days , I worked on large social portal.it consists around 90 controllers and 90 models and 700 view pages.....(http://www.computeruser.com)... it consist of videos, blogs, articles,.....etc...

according to my view...performance is not bad....you can build a any portal...using CI...
currently i am working models using CI ... models also an huge portal....You can use any number of controllers and models. and view folder....this is not at all issue........


Need tips about large CI app - El Forum - 12-06-2007

[eluser]Grahack[/eluser]
if you have many many files and if you want to easily reuse modules, have a look at Matchbox.
Of course, having loads of files won't affect performance, since you can always choose what to load.
To me, the more files you have, the more modular your app is Wink .


Need tips about large CI app - El Forum - 12-06-2007

[eluser]rogierb[/eluser]
[quote author="Grahack" date="1196960600"]
To me, the more files you have, the more modular your app is Wink .[/quote]

Well that is my philosophy... but I always struggle with the decisions when to use a new controller. Do you create a new controller on every new feature, or even on sub-features? For example "user" is a controller. Do you create a new controller when the user gets a new feature or does it depend on the complexity of the feature? So one controller fits all, or even controllers as modular as possible? And to which depth?

I'll take a look at Matchbox.


Need tips about large CI app - El Forum - 12-06-2007

[eluser]Grahack[/eluser]
This to me is very personal, I have no answer (and hope someone will have here). One thing could help me to decide: the libs and models involved. You'll load things in the constructor of the controller, so you'll want this loading to be as much factorized as possible, but you don't want to load useless things too...
Big question.


Need tips about large CI app - El Forum - 12-06-2007

[eluser]rogierb[/eluser]
So why do you load things in the contructor?
I only load the basic stuff there, everything else in the specific function.

I might be totally wrong but if a function in a class is not called, everything in it is ignored.
So I load what I need within the function.

Does that make any sense?


Need tips about large CI app - El Forum - 12-06-2007

[eluser]aart-jan[/eluser]
It does makes sense from a performance point of view, but most coders are lazy and think it takes to much time to include the right libs seperatly in each function, as many libs are required by (almost) all functions inside the controller... Wink


Need tips about large CI app - El Forum - 12-06-2007

[eluser]tonanbarbarian[/eluser]
while there is no really hard and fast rules about how MVC should be used generally you build your models as representing a database table, or similar entity.
Then you usually have a controller that performs the main actions needed for that model.

So if you have an articles table in the database you create a model called article and a controller called articles.
The controller may need to load other models to help with the management of the articles but that is ok.
However there can be situations where things do not fit that neatly.

Another thing you might want to consider on very large projects is performance. If you have a controller that has a large amount of code in it you might want to break it into several smaller controller. The reason for this is that PHP has to initially parse all of the code before it decides what is actually run, and it will have to allocate memory to store all of the code in etc etc

In this situation what I do is actually strip all of code out of the various methods and put them into seperate libraries.
The controller ends up still having all of the methods in it but each method just loads a library to do its action

For example lets say your 4000+ line controller consists of about 40 methods with nearly 100 lines of code in each method.
If you take each 100 line method and put it into its own Library you can rewrite the controller down to maybe just 100 lines of code.

Code:
class Something extends Controller {
  function index() {
    $this->load->library('SomethingIndex');
    $this->somethingindex->index();
  }

  function show() {
    $this->load->library('SomethingShow');
    $this->somethingshow->show();
  }

  ...
}



Need tips about large CI app - El Forum - 12-07-2007

[eluser]Grahack[/eluser]
That's great. Must be faster, but I'd like to see benchmarking tests. Did you have time to do that?
I don't know the internals of php enough to be sure.


Need tips about large CI app - El Forum - 12-07-2007

[eluser]rogierb[/eluser]
@tonanbarbarian: That's very clever! I guess this can be used for almost everything. Not only methods but large switches and even libraries.(libraries split into libraries, hmm) My only concern is that you might lose oversight with so many files.

But im sure going to try that on my +4000 line controller. But what to do with that +1000 line controller in it ;-)