Answer the question
In order to leave comments, you need to log in
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;
class User
{
// ...
public function getRole_name() { }
// ...
}
$user = new User;
echo 'Nick: ' . $user->user_nick;
echo 'Role name: ' . $user->role_name;
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question