Welcome Guest, Not a member yet? Register   Sign In
Advice on naming conventions and directory structure
#1

[eluser]Unknown[/eluser]
OK. So I'm building my first CI based app and I'm already realizing that some of the approaches I've taken are problematic. Before I went any farther, I thought I'd get some sage advice from some of you who have already been down this road.

In particular, what advice can you give me in terms of naming conventions and directory structures?

I started off by trying to name things consistently so, for example, I might have a "clients" controller, a "clients" view, and a "clients" model, but that become a nightmare for me in trying to remember which clients.php I was working with.

My guess is that a lot of you have settled on a certain set of standards and a basic directory structure beyond that required by CI, so perhaps you can save me (and others) some time.
#2

[eluser]sikkle[/eluser]
For my side, i go with that :

Controllers : clients.php
Model : clients_model.php let me use $this->clients_model->method();
View : method_view.php let me use $this->load->view('method_view');

Hope that help.

see ya around.
#3

[eluser]Michael Wales[/eluser]
Personally:

Controller: Plural noun (clients.php)
Model: Singular noun (client.php)
View: Class/method (client/list.php)

Views, of course, will deviate often - but that's my general rule of thumb.

Plus - you won't be able to have a client controller and a clients model - they must be unique names as you can not declare a class twice.
#4

[eluser]xwero[/eluser]
for the convience core i used

controller : any name you like
model : [controller name][suffix you like]
view : [controller name]/[method name]
validation : [controller name][suffix you like] (it's a model class but instead of data fetching and manipulation it contains the validation and action if it's true or false)
#5

[eluser]TheFuzzy0ne[/eluser]
I really like the sound of that xwero, although I'm interested to know what you do in situations where, say you have an subdirectory in the controllers directory called "admin", and in that subdirectory, you had quite a few admin controllers that required the functionality of a model that's used for another controller. Do you extend the model you want to clone, or just load the model as it is?
#6

[eluser]Dam1an[/eluser]
My approach is pretty much the same as Michaels, although I have the '_model' suffix to my models, and then just alias them to the singular when I use them
#7

[eluser]xwero[/eluser]
This thread was almost a year old Smile

TheFuzzy0ne i wouldn't change the code as i stick to the load what you need when you need it attitude. But if every controller uses the model you could use a predefined suffix to load the model and check if a model with that suffix is present in the directory the controller is in.
#8

[eluser]Dam1an[/eluser]
[quote author="xwero" date="1242159290"]This thread was almost a year old Smile[/quote]

You're right... so it is
It just appeared in my unread posts, I didn't even look at the date
#9

[eluser]Shahgeb[/eluser]
there is no any strong recommendation about the naming convention we need to follow in CI.
but normally we use here MVC naming present by R && R.




Theme © iAndrew 2016 - Forum software by © MyBB