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

WBOY
Release: 2016-07-06 13:54:09
Original
1593 people have browsed it

<code>class ★Model extends Model
{

    protected $tableName = 'abc';

}</code>
Copy after login
Copy after login

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>
Copy after login
Copy after login

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.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!