為了訂定自己的PHP+Codeigniter Framework(以下簡稱:CI) Coding Style
參考了幾個官方規範 如下:
1.PSR : http://www.php-fig.org/psr/ (PSR-1...PSR-7) (PascalCase,camelCase)
2.CI 官方命名規則 :https://goo.gl/JcM2pt (Proper_case, lower_case)
3.PHP 各framework的命名規則比較表: http://goo.gl/W0GocM (大多為PascalCase, camelCase,CI 特別古怪)
身為一個C#+PHP的開發者, 由於PHP+CI的命名規則很多是跟C#互斥的
e.g PHP:function_name (不建議使用funtionName) , C# :FunctionName(不建議使用function_name)
而且CI 幾乎都是lower_case(underscore)
最後決定採取一個不影響CI運作,且比較偏向PHP Zend Framework(PascalCase+camelCase)的命名規則
其實是因為這個Style跟C#比較像........:P
MySQL資料庫命名規則
TableName: camelCase , e.g customer , MSSQL: PascalCase,e.g:Customer
FieldName: camelCase , e.g customerName,customerID ,MSSQL: PascalCase
View: vwPascalCase, e.g vwCustomerOrder
StoreProcedure: spPascalCase , e.g spGetCustomerOrder
Trigger: trPascalCase ,e.g trUpdateCustomer
Function: fnPascalCase,e.g fnGetUserSalary
PHP+CI 檔案名稱命名規則
Model: PascalCase ,e.g CustomerViewModel.php
Controller: PascalCase ,e.g ControllerBase.php
View: camelCase ,e.g customerData.html , C#: PascalCase.html
Others: camelCase ,e.g logHelper.php , C#:PascalCase.php
PHP+CI 變數命名規則
Classes: PascalCase
properties: camelCase ,e.g protected $customerID, C# : PascalCase
methodOrFunction: camelCase ,e.g public function getCustomerOrder, setOrderStatus, C# :PascalCase
use get* set* to be getter or setter!
$localVariable:camelCase e.g getCustomerInfo($customerID);