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

#1
[eluser]parrots[/eluser]
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):

Code:
application/
    controllers/
        administration/
            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)
    models/
        administrators.php
        art.php
        stories.php
    views/
        administration/
            artwork/
                all.php
                delete.php
                edit.php
            stories/
                all.php
                delete.php
                edit.php
            login.php
            logout.php
            home.php
        artwork/
            all.php
            view.php
        stories/
            all.php
            view.php
        home.php

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

#2
[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:

system/
application/
backend/
....
frontend/
....

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

#3
[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.

#4
[eluser]John_Betong[/eluser]
Hi Parrots,

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

view folder
Code:
..

contactus.php
docs.php
formsuccess.php
hire.php
home.php
myform.php
products.php

_doctype_strict.php
_doctype_transit.php

_doc_faqs.php
_doc_links.php
_doc_privacy.php
_doc_sitemap.php
_doc_terms.php

_home_welcome.php

_com_analytics.php
_com_footer.php
_com_header.php
_com_menu_left.php
_com_pic_msg.php
_com_title.php

_hire_box.php
_hire_credit.php
_hire_cyclecarrier.php
_hire_dates.php
_hire_form.php
_hire_location.php
_hire_menu.php
_hire_vehicle.php
_home_products.php
 
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?

Cheers,

John_Betong
 

#5
[eluser]parrots[/eluser]
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-2019 MyBB Group.