Welcome Guest, Not a member yet? Register   Sign In
File structure
#1

[eluser]Svante Hansson[/eluser]
After reading up and sucessfully made a guestbook I've realised that it's hard for me to structure the file names. E.g I used one controller for it all which might work for a guestbook but I would be making a community I doubt I'd be using just one.

For the guestbook I used
/controllers/guestbook_controller.php
/views/guestbook_view.php
/views/guestbook_formsucess_view.php
/models/guestbook_model.php

which were quite messy for me as a beginner.

Lets say I would do a photo gallery, how would I structure it? If we keep it simple;
I'd need a login/registration presumably/upload (when logged in)/view gallery/pagination/profile? page

What would be models, views and controllers? Do I even need models? I'm new to this MVC concept (and to frameworks) so I am just trying to puzzle together how I would structure a project.

Thanks in advance.
#2

[eluser]jedd[/eluser]
Hi Svante and welcome to the CI forums.

I think in general your controllers should be more human readable, as they are part of the URL that everyone sees. If you need to use a suffix (I hate them, personally) then use it on the models. Ie rather than this:

Quote:For the guestbook I used
/controllers/guestbook_controller.php

... use controllers/guestbook.php and perhaps models/guestbook_model.php

As I say, though, I hate that approach, and would rather come up with a near-synonym for the model/controller relationship - or better yet, have a model that abstracts my data, and a controller that abstracts my functions. Starts to sound a bit zen, though, huh?

Quote:Lets say I would do a photo gallery, how would I structure it? If we keep it simple;
I'd need a login/registration presumably/upload (when logged in)/view gallery/pagination/profile? page

I'd have a controller called gallery probably, and a model called image or photo.

This means people would hit http://sitename.com.au/gallery - which I think is nicely succinct.

Do you need a model? Almost definitely in this case, even if you don't have any data stored in a database - the model will front-end all queries and changes to the file-system that contains your gallery, for example.

If your site is quite small, and is intended to remain that way, keep your views the one /views/ directory. But if you reckon you're going to expand it, then you can easily put views into sub-directories. I tend to put them in sub-directories that match the name of my controller (in this case views/gallery/...)
#3

[eluser]Svante Hansson[/eluser]
Thank you for your feedback!

Another question, CI User Guide suggests that a table name (e.g something I would name tbl_users) should be renamed so it'd look like this: exp_sah_users; is this correct or did I just get it all wrong (SAH being my initials thus the choice).
Do people follow these guidelines generally?
#4

[eluser]jedd[/eluser]
Some people might. Here are a sample of my table names from my current project: country, entity, forum, member, message, thread, site, taxon, activity, organism.

Note that some people swear by plurals for their table names, and putting the table name in every field name, or picking names depending on the phase of the moon .. etc.
#5

[eluser]davidbehler[/eluser]
Quote:or picking names depending on the phase of the moon
sounds like fun!

I usually have a "system" controller that handles the basics like login, registration, forgot password and so on. Apart from that one I have a controller for every major "category", in your case I would have a "gallery" controller with the functions "view" and "upload" I guess..same scheme goes for the other examples you mentioned. But what about that "pagination" thing? Why would you have an extra controller/function for that?




Theme © iAndrew 2016 - Forum software by © MyBB