Codeigniter: html output in wrong order

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
seandisanti
php-forum Fan User
php-forum Fan User
Posts: 973
Joined: Mon Oct 01, 2012 12:32 pm

Wed Apr 09, 2014 9:29 pm

The point of using an MVC framework is to separate your php from your html, and your business rules from your data. I'm not saying that to pick on you or your effort, but to remind you and to save you some headaches.

First, identify your objects, presumably you'll have a gallery object, and an image object (assuming it's just a gallery of images, but it would work the same with any other kind of thing that you're posting in your gallery).

For each of your objects, identify what properties you need to access, store, and modify from the data. Those become the properties that you define in the model for the object.

Your controller, again for each object would be a collection of functions that define the functionality of the object, business rules etc. For example, instantiating a gallery object could create image objects for each of the images associated with that gallery, Loading a gallery view would be as simple as having the gallery display the view of each of it's member images.

The last thing to worry about is the view. Assuming that you've done the rest carefully and methodically, your view is going to be a very simple display. Think of it like a mail merge in the old days, you would write a letter to be sent to a customer, and would design the whole layout with placeholders for the data that you knew would be populated by another step in the process. The view is the same way, by the time the view is being loaded, all of the information for the object is already available because it's been retrieved in the model, manipulated and formatted by the controller, and then displayed by the view.

Any type of MVC framework is going to take a little bit of time to get used to, but you'll make your job a lot easier by using the components as they're intended, and the rest will pretty much fall into place. There are a lot of good resources online for codeigniter and other MVC frameworks, check out the 'jream' channel on youtube, and jream.com for some plain language explanations and demonstration of MVC, his stuff helped me a lot when i was fist getting started.

seandisanti
php-forum Fan User
php-forum Fan User
Posts: 973
Joined: Mon Oct 01, 2012 12:32 pm

Fri Apr 11, 2014 5:54 pm

I'm glad to help, and jream has some great stuff, even a premium course on code igniter, but the premium courses aren't free

seandisanti
php-forum Fan User
php-forum Fan User
Posts: 973
Joined: Mon Oct 01, 2012 12:32 pm

Sat Apr 12, 2014 8:09 pm

basically your view of a member of the gallery would just be a small block of html, that formats and displays the data. Then the Gallery view would load the views of each of it's members. I think it'll make more sense when you're going through the videos

Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 9 guests