• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Model / Controller names

Hi all. I'm just getting started with CI for my newest projects and so far it's been wonderful. I had a question for everyone though, with regards to how they structure their applications, specifically large ones.

I'm planning on using the active record setup for databases found on the wiki for my next (much larger) project. This requires (or at least encourages) one to name the models the singular name of their database tables. Which means, for example, "Page", "Story", etc.

Now, I had been naming my controllers something similar: "/administration/stories" or "/administration/stories/edit/12" (administration is a folder, stories is a controller, to ensure I don't have an "administration" controller that's huge) and so on. However, sometimes the singular and plural of the name can be the same (ex "art"). If I name both the controller and the model "Art", obviously I get an error since I have two active classes are named the same thing. For the controller I can name it "artwork" or something, but I wanted to see how else people have approached this.

Here is my current layout strategy for one site (trimmed for your reading pleasure):

            artwork.php (methods:edit, delete, view all)
            stories.php (methods:edit, delete, view all)
            welcome.php (methods:login, logout, main admin page)
        artwork.php (methods:view all, show individual)
        stories.php (methods:view all, show individual)
        welcome.php (homepage)

I haven't seen much in the way of best practices for controller/view/model layout when you have an admin section, active recod models and the likes, so I was just wondering what everyone else has found works best, with large projects especially. I'd like to avoid going crazy as this site grows Wink

[eluser]Majd Taby[/eluser]
Here's how I have mine setup (I got this idea from #codeigniter)

I have two separate applications on the same codeigniter setup, so here's how my structure looks:


This way it's a lot easier to work with and i **think** it adds an extra layer of security

[eluser]Michael Wales[/eluser]
I tend to name all of my controllers the plural (stories, users, etc) and the model the singular with an appended '_m' (story_m, user_m).

I run into a bit of an issue with my plurals and tend to do a lot of URL routing though. Sure domain.com/stories is great for listing the stories on your site, but domain.com/stories/the-title-of-a-single-story is a bit odd to me (using the plural stories when viewing a single story).

The combination may be a bit quirky, but it works for me.

Hi Parrots,

I have written a couple of sites and the last one adopted this following style:

view folder






As you may presume from the naming convention I have:

1. a controller and view with the same name.
2. all files prefixed with “_xxxx” are assocated with the “xxxx.php” controller and view.
3. files prefixed with “_com” (common) can be used with all views.

This worked well and especially because:
1. my editor automatically lists the files alphabetically.
2. I find it a pain to keep switching directories.
3. updates are easier when only the controller and view directories change.

Discuss: Are programmers lazy or efficient?



Thanks guys, you've given me a few ideas to toy around with before I start production. I like your idea of appending _m to the end walesmd, I'll just need to look into how much the ActiveRecord class will like that. Hopefully it won't mess up with relationships between tables.

As for your question John_Betong, I tend to lean towards efficient. Lazy usually comes back to bite you, efficient, while appearing lazy sometimes, is usually thought out.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.