Skip to content

Instantly share code, notes, and snippets.

@bkvaiude
Last active August 29, 2015 14:13
Show Gist options
  • Save bkvaiude/264c385a5df5fced4fa2 to your computer and use it in GitHub Desktop.
Save bkvaiude/264c385a5df5fced4fa2 to your computer and use it in GitHub Desktop.
MVC framework coding standards (Codeigniter, CakePHP, Django, Pylon, F3, Laravel, etc...)
Objectives
----------
* Basic things (https://www.drupal.org/coding-standards)
* Coding standards for a Model
* Coding standards for a Behaviours
* Coding standards for a Controller
* Coding standards for a Components
* Coding standards for a View
* Coding standards for a Helper
* Coding standards for a Utilities
* Coding standards for a Model
1 - In ideal case, Model represents the single table into the database. So no. of Models = no. of Tables
2 - Model Class name must be in CamelCase.
Ex. Student, AccountDetail
3 - In databaase, table name must be written in plural.
Ex. students, account_details
4 - Funcation name must be in CamelCase.
Ex. getStudentInformations(), updateStudentMarks()
* Coding standards for a Behaviours
1 - Class name must be in CamelCase.
2 - Funcation name must be in CamelCase.
Ex. cascade_teacher_updates()
* Coding standards for a Controller
1 - Controller Class name must be in CamelCase.
Ex. Student, AccountDetail
2 - Action name must be in snake_case.
Ex. show_profile(), delete_account()
* Coding standards for a Component
1 - Class name must be in CamelCase.
2 - Funcation name must be in snake_case.
Ex. send_notifications_to_parents()
* Coding standards for a View
1 - View file must be same as controller action name.
2 - Kick out all common code from template and write into the layout template or in partial template.
* Coding standards for a Helper
1 - Class name / file naeme must be in CamelCase.
2 - Funcation name must be in snake_case.
Ex. active_menu_bar()
3 - Helper functions are directly accessible through the template, so write reusable template code into the helpers
* Coding standards for a Utilities
1 - Class name / file naeme must be in CamelCase.
2 - Funcation name must be in snake_case.
Ex. active_menu_bar()
3 - Helper functions are directly accessible through the template, so write operational code into the helpers
CamelCase Vs. SnakeCase
As there are chances of having same function name in to the controller and model, so writing function name in differnt cases will help developer idenity function source.
For more details about MVC design pattern, please go through the following link
http://stackoverflow.com/questions/14044681/fat-models-and-skinny-controllers-sounds-like-creating-god-models
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment