D
D
Dmitry Baibukhtin2014-10-07 23:47:53
Yii
Dmitry Baibukhtin, 2014-10-07 23:47:53

How to write getter and relation names in Yii: camel case or underscore?

Hello. Such a problem:
In the model, attributes are written through underscores, like the names of fields in the database. I need to write a getter for a certain attribute (I won't write for everyone, it's superfluous). In what style should the name of the getter be written?
Option 1: Write the name of the getter in camelcase
For example public function getRoleName()
Problem:
As a result, camelcase and underscore are mixed in the form. For example:

echo 'Nick: ' . $user->user_nick;
echo 'Role name: ' . $user->roleName;

Option 2: Write the name of the getter with an underscore
. For example, public function getRole_name()
Problem:
As a result, a camelcase and an underscore are mixed in the class, generally a cesspool, and no code is obtained. For example:
class User
{
// ...
    public function getRole_name() { }
// ...
}

$user = new User;
echo 'Nick: ' . $user->user_nick;
echo 'Role name: ' . $user->role_name;

How are you doing?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim, 2014-10-07
@PiloTeZ

PSR-1
PSR-2

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question