ThinkPHP learning note instantiation model four methods
Source: Internet
Author: User
Create Action Class [php] & lt ;? PhpclassNewObjectActionextendsAction {publicfunctionindex () {// 1. create a basic model //// 1: instantiate the database operation class of a system /// newModel (& amp ;... "/> create an Action Class [php] Select (); // dump ($ list); // Two: Cross-model operation; instantiate a table, at the same time, instantiate a self-written database operation class // mostly used to extract some public business logic to form a public Model ///M ('user', 'commonmodel ') equivalent to new CommonModel ('user'); model is automatically loaded // $ user = M ('user', 'commonmodel '); // $ user = new CommonModel ('user'); // $ list = $ user-> select (); // dump ($ list ); // $ user-> modelTest (); // 3: instantiate a user-defined model. // multiple models are used for businesses that do not need to be more complex. // 1. create a model manually and create a custom model for the user table, which can encapsulate the functions provided by thinkphp. // $ user = new UserModel () If the model does not exist in D ('user'); // if the model does not exist, an exception is thrown and only one instance is used. the default value is, only models under the current application can be called // $ user = new UserModel (); // $ list = $ user-> select (); // dump ($ list ); // $ user-> modelTest (); // 4. instantiate an empty Model. it is a traditional SQL statement. you need to add the table prefix // $ user = new Model (); $ list = $ user-> query ('select * from tb_user '); dump ($ list); // group: D ('admin. user ') ;}}?> Two models: [php] [Php]
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