Florian30
(Florian H Petter)
June 18, 2014, 7:20am
1
Hello,
how should database fields be named in Yii2?
first_name or firstName?
Yii 2 Core Framework Code Style
===============================
The following code style is used for Yii 2.x core and official extensions development. If you want to pull-request code
into the core, consider using it. We aren't forcing you to use this code style for your application. Feel free to choose
what suits you better.
You can get a config for CodeSniffer here: https://github.com/yiisoft/yii2-coding-standards
## 1. Overview
Overall we're using [PSR-2](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)
compatible style so everything that applies to
[PSR-2](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md) is applied to our code
style as well.
- Files MUST use either `<?php` or `<?=` tags.
- There should be a newline at the end of file.
- Files MUST use only UTF-8 without BOM for PHP code.
- Code MUST use 4 spaces for indenting, not tabs.
This file has been truncated. show original
"Property names MUST be declared in camelCase" … but also for active records (db fields)?
e.g. "person" table:
first_name = db field
last_name = db field
fullName = getter
echo $person->first_name;
echo $person->last_name;
echo $person->fullName;
.?!
Thanks!
Florian
samdark
(Alexander Makarov)
June 18, 2014, 7:46am
2
First variant is a bit more safer because you’re avoiding case sensitivity issues that present in many DBs. Different naming for DB fields is telling you these are from DB.