Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

How to go abuot redesigning my web app for MVC

Options
  • 30-08-2009 1:53am
    #1
    Registered Users Posts: 2,228 ✭✭✭


    Hi,

    I have recently made up an a simple web app to track the delivery of products from suppliers and manage stock levels.

    I want to convert this to a codeIgniter MVC web application.

    I have been reading the tutorials but im still unsure about how to gou about modelling the site..

    Am I supposed to model this like a class diagram etc where there is a class for each entity?

    Example: Some entities are Transaction, Product, Depot, Supplier and another would be HomeScreen where I give statistics etc..

    Do I create a controller class for each one of these along with a view_page..?

    Stumped here! Sorry, If this post is a bit scattered but i'm very tired now and even more frustrated..thanks.


Comments

  • Registered Users Posts: 3,361 ✭✭✭randombar


    I've been messing around trying to get to grips with codeigniter for the last couple of weeks.

    Basically my understanding, every db table should have a model, most pages have a controller which would have a view associated. In each view you have embedded views for header footer etc.

    There are a few different arguments about the pros and cons of each method but that one makes the most sense to me


  • Closed Accounts Posts: 975 ✭✭✭squibs


    Before you commit to codeigniter, you might want to look at Zend Framework. The helper classes are more useful, to my mind. I also think that the extra work involved in creating an MVC app becomes worth it only when you have a mid sized to large app - a basic small CRUD app may not be a good candidate for MVC.


  • Registered Users Posts: 2,228 ✭✭✭techguy


    GaryCocs wrote: »
    I've been messing around trying to get to grips with codeigniter for the last couple of weeks.

    Basically my understanding, every db table should have a model, most pages have a controller which would have a view associated. In each view you have embedded views for header footer etc.

    There are a few different arguments about the pros and cons of each method but that one makes the most sense to me

    I've just used controllers and views so far..I haven't really looked at Models yet. I'm making an application to track the movement/stock levels of products between different depots. I have a controller for products,customers,transactions and reports..I then have multiple views for each of these which are decided using functions. I have probably gone a bit overkill on the controllers but what the heck.
    squibs wrote: »
    Before you commit to codeigniter, you might want to look at Zend Framework. The helper classes are more useful, to my mind. I also think that the extra work involved in creating an MVC app becomes worth it only when you have a mid sized to large app - a basic small CRUD app may not be a good candidate for MVC.

    I looked at Zendm, in fact, Zend was my first port of but the tutorials were a bit weird. Like I didn't even know where to start programming or anything? Then I looked at CI and the tutorials were a lot more straightforward. I will stick with CI for the moment an will probably move on to Zend after. I'd say Zend is more or less industry standard at this stage, would I be right?

    Also, how basic do you mean when you say basic? My app really only displays different query results and reports from the database with a few form etc. I had actually made the application without a framework but it's a nightmare to change something... I have to hack the changes into effect i.e. any change breaks a whole section of the app then I have to patch each break until it works.. Time consuming and not the way things should be done.

    I suppose my app is basic but at least I get to learn something new and I can say i've built a web app using a well known framework..:pac:


  • Registered Users Posts: 3,361 ✭✭✭randombar


    techguy wrote: »
    I've just used controllers and views so far..I haven't really looked at Models yet. I'm making an application to track the movement/stock levels of products between different depots. I have a controller for products,customers,transactions and reports..I then have multiple views for each of these which are decided using functions. I have probably gone a bit overkill on the controllers but what the heck.

    Ya I just have one controller with a few different methods in it at the moment, I think it might help with the urls until I sort out the .htaccess a bit more.

    As for the models, I think you should basically do the same as you are doing for the controllers a different model for products,customers,transactions and reports. Basically all DB calls should come from the models and not the controller.

    My problem at the moment is I find myself doing a bit of coding in the views but I think that is mainly due to the fact that my OOP is a bit rusty and my css could probably do with an overhaul..


  • Closed Accounts Posts: 975 ✭✭✭squibs


    It's definitely good to learn an MVC framework, and a practical project is the way to do it. It does seem to be a common perception that codeigniter is easier to pickup.

    In terms of updates being difficult with your current app, are you doing modular OOP scripts, bundling common functions in include files, looking at third-party class repositories like PEAR, etc? An MVC helps to organise you, but its possible to write maintainable code without one, IMO.


  • Advertisement
  • Registered Users Posts: 216 ✭✭KJF


    Coming from a Ruby on Rails background where MVC is the default pattern used when building web apps I would advise the following to anyone starting out with MVC.

    Its better in the long run if you try and follow this one convention:
    Keep your controllers lean and your models fat. What I mean by this is:

    The controller should only be used for the browser type stuff. i.e. parsing user requests, data submissions, cookies, sessions.

    For everything else, stick it in the model. The model should talk to the database, store and validate data and perform all the business logic. All the heavy lifting should be done here.

    Keeping your controllers and models this way makes everything much easier to test and makes future changes to your code much easier to manage.


  • Registered Users Posts: 2,228 ✭✭✭techguy


    squibs wrote: »
    It's definitely good to learn an MVC framework, and a practical project is the way to do it. It does seem to be a common perception that codeigniter is easier to pickup.

    In terms of updates being difficult with your current app, are you doing modular OOP scripts, bundling common functions in include files, looking at third-party class repositories like PEAR, etc? An MVC helps to organise you, but its possible to write maintainable code without one, IMO.

    My app is like one big bowl of spaghetti, nothing less! I have written no functions let alone classes. It started off as a small idea and now it's a semi finished load of crap coding. That's when I decided it was time to learn a MVC framework.
    KJF wrote: »
    Coming from a Ruby on Rails background where MVC is the default pattern used when building web apps I would advise the following to anyone starting out with MVC.

    Its better in the long run if you try and follow this one convention:
    Keep your controllers lean and your models fat. What I mean by this is:

    The controller should only be used for the browser type stuff. i.e. parsing user requests, data submissions, cookies, sessions.

    For everything else, stick it in the model. The model should talk to the database, store and validate data and perform all the business logic. All the heavy lifting should be done here.

    Keeping your controllers and models this way makes everything much easier to test and makes future changes to your code much easier to manage.

    Thats great advice, thanks. I will probably start into a few models this evening.

    Any tips on how to look at designing models. I was thinking something along the lines of one model per controller..

    My current setup is: one controller per page section (transaction/depot/product) with a few different views associated with each controller. At the moment each view has its own function to load the view etc.

    Is it possible to have a form page display the form first and then a success/fail page within one view. You know, like you do with PHP on it's own..


  • Registered Users Posts: 3,361 ✭✭✭randombar


    techguy wrote: »

    Is it possible to have a form page display the form first and then a success/fail page within one view. You know, like you do with PHP on it's own..

    Ya, that should be easy to do depending on your code, remember codeigniter has some pretty decent validation classes etc.

    This topic helped be quite a bit: http://codeigniter.com/forums/viewthread/123948/


  • Closed Accounts Posts: 181 ✭✭Occam


    techguy wrote: »
    My app is like one big bowl of spaghetti, nothing less! I have written no functions let alone classes. It started off as a small idea and now it's a semi finished load of crap coding. That's when I decided it was time to learn a MVC framework.

    I don't mean to be harsh, but given that you've just produced a "load of crap coding" what you should be doing is learning how to code properly, not learning how to apply a fancy design pattern and a web framework.

    MVC is not a silver bullet for your problems, especially if you are struggling with OO design - you will just tie yourself up in even greater knots.


  • Registered Users Posts: 2,228 ✭✭✭techguy


    Occam wrote: »
    I don't mean to be harsh, but given that you've just produced a "load of crap coding" what you should be doing is learning how to code properly, not learning how to apply a fancy design pattern and a web framework.

    MVC is not a silver bullet for your problems, especially if you are struggling with OO design - you will just tie yourself up in even greater knots.

    I suppose thats the kind of reply that I deserved.. Bad choice of words. The coding isn't a load of crap when you look at each page individually, everything works fine but then when you take a broader look and view the whole application then it doesn't look so good, mainly because there is a lot of code copying etc and when you go to change one thing you will probably break that whole function.

    While I don't have much experience with OOP I wouldn't say I struggle with it. I understand the basics but just havent really used it yet in an application.

    I'm actually really enjoying using Codeigniter now because it is demonstrating an OOP approach to things.

    I'm quite happy with my progress with CI now, my next task is to introduce models and then get my htaccess working to get rid of "index.php" so far all attempts have failed :(


  • Advertisement
Advertisement