Home  >  Article  >  Backend Development  >  thinkphp5 - What is the use of this attribute in thinkPHP custom model.class.php?

thinkphp5 - What is the use of this attribute in thinkPHP custom model.class.php?

WBOY
WBOYOriginal
2016-07-06 13:54:091597browse

<code>class ★Model extends Model
{

    protected $tableName = 'abc';

}</code>

What is the use of the $tableName attribute?
Isn’t the ★ part the table name?
Why create another protected $tableName = '◆';
If ◆ is the same as ★, then it will be repeated. Yes, I did it many times,

If it is different, then when $mydb = D("★") is created, the file will not be found?

Reply content:

<code>class ★Model extends Model
{

    protected $tableName = 'abc';

}</code>

What is the use of the $tableName attribute?
Isn’t the ★ part the table name?
Why create another protected $tableName = '◆';
If ◆ is the same as ★, don’t repeat it Yes, I did it many times,

If it is different, then when $mydb = D("★") is created, the file will not be found?

The name of the model can be different from the name of the data table, which is more flexible. For example, the data table is pre_q_a, and the model name can be QaModel,
protected $tableName = 'q_a'

This is due to the naming problem of PHP and SQL databases:
PHP classes are named using camel case, such as UserGroup; methods are named using camel case, such as public function getUserInfo(){}; PHP functions are named using lowercase letters and The format of underscores, such as function get_string_length(){};
MySQL database tables and fields basically use lowercase letters and underscores, such as table name user_group, field name create_time.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn