Welcome Guest, Not a member yet? Register   Sign In
newbie at CI and MVC
#1

[eluser]brancher[/eluser]
hi.

i was wondering about the right way to do the following:

suppose that I need to exhibit a PROJECT that contains, basically, 2 sections:
- the first one with a text about the PROJECT;
- the second with lots of images, divided into categories that are shown separated from each other.

starting from a scratch, without CI, i would have an object for the PROJECTS an another one for the IMAGES, right? and, on the PROJECT object, have a method to instantiate IMAGEs objects. right?!

doing it in MVC/CI, how should i proceed? creating a model for PROJECTS and another for IMAGES and calling them both from the controller? or should i do something different?

thanks for the help. sorry about the newbie question.

cya.
#2

[eluser]TheFuzzy0ne[/eluser]
Welcome to the CodeIgniter forums!

There'd be no change. If you project class instantiates the image class, you'd just instantiate the project class from your controller.
#3

[eluser]brancher[/eluser]
fuzzy

but how should that occur in CI? if I try to instantiate the IMAGE model whitin the PROJECT model, it returns an error (trying to load a method in non-object or something like that).

or i am doing something really wrong?

thanks.
#4

[eluser]jedd[/eluser]
Hi Brancher,

Can you come back a bit, and describe roughly what you want to display, on-screen? From your original post I gathered you wanted the text and a navigation/image section, both displayed at the same time. Can you also explain how you think this data will be stored - I'm assuming you're talking about a DB, so a v.rough idea on tables and relationships.

In general terms, if you can avoid calling models from other models, your life will be easier. Your controller dictates / reflects what the user sees and does, while your models are the interface to the way your data is stored. So to answer your last question, yes, what Fuzzy was saying was that you'd load your models from your controller - not from each other.
#5

[eluser]brancher[/eluser]
hey jedd

thanks for your attention.

well, you answered what i need to display on the screen. suppose the project i mentioned before is an ARCHITECTURE project and i need to show all thumbnails within one image category (like drawings or construction photos) as well the information about the project (like title, date of execution, localization, etc.).

for now, i understand the following: i should load the model PROJECTS, call a method get_project($project_id) assigning the return value to an array. then, load the model IMAGES, call a method like get_project_images($project_id), assigning the return to a new array an, then, pass both arrays to the view. that is it? is it the best way?

thanks,
brancher
#6

[eluser]jedd[/eluser]
Hi Brancher.

Yup, that's pretty much it. Your logic (in the sense of the application) goes into the controller. It talks to whatever models it needs to, to collate and integrate the data that it pulls from the model(s). The trick, obviously, becomes one of designing your data store, and your models on the front of that, to make this as easy as possible.

Note that some people recommend the one-model-per-table approach (classic Active Record). You are not obliged to do this, and indeed you may find in this example that having a single model fronting all your project-related data - tables, images, etc - works better for you.




Theme © iAndrew 2016 - Forum software by © MyBB