7

I'm pretty new to OO PHP, however i get how it all works and am ready to start building an MVC for a big site i'm working on. I know it isnt necessary written that you must do it like this but there's gotta be some normal practises....

class names - camelcase? underscores?

class files - same as class?

url/post/get controll name - router.php?

any other things i should be aware of before i embark?

Haroldo
  • 36,607
  • 46
  • 127
  • 169

6 Answers6

10

It doesn't really matter how you name things as long as you are consistent.

If you are interested in taking a look at coding standards:

Yacoby
  • 54,544
  • 15
  • 116
  • 120
1

http://framework.zend.com/manual/en/coding-standard.naming-conventions.html Should be your bible as a PHP developer.

Mikushi
  • 3,311
  • 4
  • 19
  • 22
1

Class constants are generally all uppercase, Class names are generally like java with capital first letters SomeClassName

Beyond that, I guess it depends who you ask

Mitch Dempsey
  • 38,725
  • 6
  • 68
  • 74
1

Try this: https://stackoverflow.com/questions/332831/php-best-practices-for-naming-conventions/332854#332854

It's not at all what you asked, but do consider looking at one of the literally dozens and dozens of existing MVC-style PHP frameworks. You can save yourself a lot of time and generally get better quality if you use a solid existing framework.

Community
  • 1
  • 1
Funkatron
  • 912
  • 5
  • 13
1

In terms of MVC logic, at least separate your control and presentation. I'm working with Wordpress, which looks extremely horrible in places, especially admin side. For my own part, I have the controller validate the $_REQUEST, make changes to the data by interacting with the database, and then instantiate an appropriate view class.

Fletcher Moore
  • 13,558
  • 11
  • 40
  • 58
1

Preferred Directory Structure: My/Class.php

ClassNames: My_Class

If you are using a modular MVC structure, make sure you have the namespace included in your bootstrap.php [this is Zend Framework specific, but I imagine there must be something similar for other mvc frameworks).

what else...the views naming - the default is dropDownAction() becomes drop-down.phtml in Zend Views.

Mallika Iyer
  • 700
  • 2
  • 12
  • 23