Welcome Guest, Not a member yet? Register   Sign In
Naming convention for M V C including file names
#1

[eluser]bengrice[/eluser]
Hi there,

Im just starting a new project and i want to start things right.

Iv been reading for ages and i cannot find a simple answer for the question.

Whats the best practice (for CI) when naming M's V's an C's and there file name.

IE

I have controller control panel, with a view and a model, this is the kind of structure i want:

controllers/ControlPanel.php (for file name, do i use camel case and or underscore etc)
then inside controller what the class name? is it class 'ControlPanel' exten.. or Control_panel... (im assuming it should match the file name)

then views and models, i want them im subfolders based on the controller eg:

views/controlpanel/userList.php (again camel case file name or underscores) same with models and model class names eg models/controlpanel/userList.php

any advice / clarification would be greatly appreciated

many thanks

ben
#2

[eluser]Jondolar[/eluser]
You might find the info you are looking for in the CI style guide:
http://ellislab.com/codeigniter/user-gui...guide.html

See the "Class and Method Naming" section.
#3

[eluser]Colin Williams[/eluser]
Hold on a minute, Jondolar. Are you telling me there is an entire web site that guides users developing with CodeIgniter, and it touches on important topics like this. Incredible. Just, incredible? Wow. Thanks for sharing that with us.
#4

[eluser]Jondolar[/eluser]
No, I was only pointing out the style guide.

Did you have anything of value to add? I did. I pointed the user to a document that may not have been obvious to find. In fact, the OP stated that he could not find the documentation.

I'm sure you just had a bad day or maybe couldn't find any other posts to tread on :-)
#5

[eluser]bengrice[/eluser]
Jondolar, thanks but i had already red this.

and for the sake of collin (who i feel may be a bit slow), by the way thanks for the very helpful comment collin, good job :roll:

unless im missing something, there is still nothing about files names or model and view names and file names?

thanks
ben
#6

[eluser]wiredesignz[/eluser]
You are missing something obviously. Read it again.

Quote:Class names should always have their first letter uppercase, and the (PHP4) constructor method should match identically.

Multiple words should be separated with an underscore, and not CamelCased.

All file names should be lower class, except for library file names which should be uppercase first character.
#7

[eluser]John_Betong[/eluser]
 
 
maybe also look at the source code in the ./system directory.
 
 
#8

[eluser]Colin Williams[/eluser]
Quote:Did you have anything of value to add? I did. I pointed the user to a document that may not have been obvious to find.

And for that I believe to get a neat little sticker.

Forgive me for holding people to a higher standard than they think they deserve. It is just funny to me that CodeIgniter is a MVC framework, and the Model, View and Controller pages of the user guide all cover this topic, and then the style guide clears it up.

Model:
Quote:...Model_name is the name of your class. Class names must have the first letter capitalized with the rest of the name lowercase. Make sure your class extends the base Model class.

The file name will be a lower case version of your class name.

View:

Quote:name is the name of your view file. Note: The .php file extension does not need to be specified unless you use something other than .php.

Okay, nothing about camelCase here. You're good to go with that, but you might want to still stick to the style guide and go lowercase and underscore.

Controller:

Quote:Using your text editor, create a file called blog.php, and put the following code in it ... Note: Class names must start with an uppercase letter.

I just suppose that if I bought a refrigerator and was trying to install it, the page in the manual titled "Installing Your New Refrigerator" might not be good to ignore, otherwise there's a good chance I will run into problems.

And hey, sometimes I pick my battles here. If that bothers anyone, click "Ignore" on any of my posts. I've got my own ignore list building up nicely. And I'll try to not be such a jerk, but I say that to my wife everyday, and...
#9

[eluser]bengrice[/eluser]
Well so far collin, after all you jibber jabber you have not actually answered my question.
Yes i can read and yes i did read the style guide etc, however you say it clears it up... well it obviously doesn't or i wouldn't be asking the question now would i...

Quote:The file name will be a lower case version of you class name
where did you find this, can you show me in the style guide please?

also wiredesignz, i can read thanks, theres no point in just quoting the guide because again i obviously didnt find what i needed.
again unless ive missed something (which i may have fair enough) where did you read this:
Quote:All file names should be lower class, except for library file names which should be uppercase first character.

and collin, what about if the refrigerator manual doesn't tell you quite what you wanted to know. i suppose you would just sit there wondering why you coke was warm ay. No i suspect you would ask a simple question on a forum (ow yes, like this) for a quick answer that would have taken a man of your 'higher standard' about 30 seconds to reply.

those others, ie John_Betong, Jondolar thanks for the simple answers, i hope i dont run into anymore problems down the line im worried i might get shouted at if i ask the wrong question Smile
#10

[eluser]wiredesignz[/eluser]
Read the "Naming Conventions" section from "Creating your own libraries", it's not really difficult to understand.

Also read "Anatomy of a Model" in the "Models" chapter for the model file naming convention.




Theme © iAndrew 2016 - Forum software by © MyBB