PHP Framework-thinkphp Does the D method have to have a corresponding database?

Source: Internet
Author: User

Before doing a small project code

class LoginController extends Controller {    public function login(){        $Admin = D('Login');        //实例化Admin模型        if ($Admin->create()){        //创建数据模型            $user = I('post.name');                    $this->session($user);            $this->success('Login success!',"/hc_tp/Admin");        //跳转到内页面        }else {            echo $this->error($Admin->getError());        }    }}

The data table prefix _login of the D method is not present here,

When you re-make a new project today, remind me of this, the data sheet does not exist.

To solve, forget that it was a TP to configure or how

Reply content:

Before doing a small project code

class LoginController extends Controller {    public function login(){        $Admin = D('Login');        //实例化Admin模型        if ($Admin->create()){        //创建数据模型            $user = I('post.name');                    $this->session($user);            $this->success('Login success!',"/hc_tp/Admin");        //跳转到内页面        }else {            echo $this->error($Admin->getError());        }    }}

The data table prefix _login of the D method is not present here,

When you re-make a new project today, remind me of this, the data sheet does not exist.

To solve, forget that it was a TP to configure or how

A data table with the same name as the model name is defaulted to the corresponding datasheet.

The login model corresponds to the login table by default,
If you do not want this to correspond, you can use
protected $tableName = ' tableName ';
Specify the data table name

Think the name of the model in PHP must be a table name

The internal implementation of the D method is the instantiation of the specific data table class

You can set up a virtual model

class LoginModel extends Model {    protected $autoCkeckFields = false; //关闭检测字段}

Not necessarily! should be d (modelname); The default modelname corresponding to the table name, does not correspond to the words will be error, but you can pass
protected $autocheckfields = false; To turn off auto-correspondence so that you can do whatever m (any table name) in the model

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.