Welcome Guest, Not a member yet? Register   Sign In
Porting existing to CI from a newbs POV
#1

[eluser]CI_Newb[/eluser]
Being a self taught programmer, I'm learning as I go. I wrote a pretty big application for my company which works well but it's very chaotic in design.

After looking into CI, how it works and how the whole MVC approach makes sense, I decided to rewrite the entire app using CI. I've watched just about all the video tutorials, read the user guide a few times and googled my arse off learning what I can.

Now I'm in no hurry, trying to do this right and really learn and use CI to its fullest. Basically what I'm doing is take a basic part of the app and redo it using CI, test it and study the code.

It's so far been going very smooth, learning a lot in the process, and really having to dig for solutions to problems I run into.

Here are some questions that come to mind:
1) Is this the way to port an existing app to CI for a newb?
2) I'm using the MVC approach but I have to wonder, is or when is acceptable to query the db from a view file?
3) Being consistently worrying that my controllers and models are too huge. I got a controller that's already 10 functions and 250 lines of code long. Is that too long? When should I be thinking that a controller / model is too big?
4) I sometimes have issues reusing models for similar things so I make a new function to do the same as the other function but with a slight change. Tips?

Thats all I can think of right now, any advise, tips, tricks would be great!
#2

[eluser]jeremydt[/eluser]
Please take what I'm about to say with a 'grain of salt' because I too am fairly new and self taught. This being said, I too am in the process of migrating an app to codeigniter for work.

Here's what I've learned:

* Fat Model, Skinny Controllers. Basically I've put as much as I can into the Models so that when I read the controller I can see what it is that I'm trying to achieve without sifting through lines and lines of code. So, my models aren't just for interacting with the databases, they do almost everything.
* I break my models up; models for validation; models for CRUD; models for utilities (like validating if a user is logged in or something, or uploading a file to the server).
* I really liked the CodeIgniter from scratch guide on tutsplus http://net.tutsplus.com/tutorials/php/co...ular-data/ (that's the link to the most recent tutorial, within the tutorial are links to the other 15 lessons)
* Because I'm rewriting the code for an app that already exists, like you, I'm taking my time cause I don't have a deadline. Because there is no deadline I'm commenting my code as I go along in case I leave the organisation and someone else has to pick it up.
* I reuse my models wherever I can.

I know I didn't answer your questions directly but I hope you might find value in some of the things that I've learned.
#3

[eluser]CI_Newb[/eluser]
Thanks for the info jeremydt.

One thing you mentioned though is that you use fat models and skinny controllers which I heard on the video tutorials. What I'm pondering is what would someone consider a skinny controller? 10 functions? 100 functions?

I'm just afraid of getting too far and having 9000 controller files for 4 pages or 1 controller with 400 functions lol
#4

[eluser]jeremydt[/eluser]
[quote author="CI_Newb" date="1286814538"]Thanks for the info jeremydt.

One thing you mentioned though is that you use fat models and skinny controllers which I heard on the video tutorials. What I'm pondering is what would someone consider a skinny controller? 10 functions? 100 functions?

I'm just afraid of getting too far and having 9000 controller files for 4 pages lol[/quote]

My view is if you're keeping your controllers as skinny as possible, whatever is best for your application is best.

When I planned my application I wrote down all the things that I required the application to do; then I grouped them into an appropriate controller. I also divide my models into subdirectories (per controller); I've found this has helped a lot. This probably wouldn't be applicable for all applications though; but, it did work for me in this particular app.
#5

[eluser]bl00dshooter[/eluser]
Quote:1) Is this the way to port an existing app to CI for a newb?
Sure.

Quote:2) I’m using the MVC approach but I have to wonder, is or when is acceptable to query the db from a view file?
You should create a function in your model, like getSomething, and return the data from the db. Then, call the function in the controller, and pass that info to the view.

Quote:3) Being consistently worrying that my controllers and models are too huge. I got a controller that’s already 10 functions and 250 lines of code long. Is that too long? When should I be thinking that a controller / model is too big?
Your controller size is proporcional to your application size. Of course, if your website only does a hello world, it won't be 250 lines big. But, if it's a e-commerce, blog, etc. it will probably be bigger then that. Ideally, you should have one controller per page. Ex: mywebsite/users = users controller; mywebsite/products/123 and mywebsite/products/155 = products controller, etc. Also, there is no problem in having functions that the user can't access thru the url, just make them private, by adding an underscore before their name, ie: _myPrivateFunction

Quote:4) I sometimes have issues reusing models for similar things so I make a new function to do the same as the other function but with a slight change. Tips?
Example with code, please?




Theme © iAndrew 2016 - Forum software by © MyBB