class NewObjectAction extends Action{
public function index(){
//1. Create a basic model
// //1: Instantiate a system database operation class
// //new Model('User') is equivalent to M('User'), placing a table that needs to be operated on in the Model
// //1 Naming:
// // thinkphp has a table name prefix by default, if it is think_user; you can use User or user to obtain it in the Model
// // If it is think_user_message; then use Model('UserMessage'); uppercase means adding a _ in front of the table name
// $User=new Model('User');
// //Call query method
// $list=$User->select();
// dump($list);
// // 2: Cross-model operation; instantiate a table and instantiate a database operation class written by yourself
//Mostly used to extract some public business logic to form a public Model
// //M('user','CommonModel') is equivalent to new CommonModel('user'); model is automatically loaded
//// $user=M('user','CommonModel');
// $user=new CommonModel('user');
// $list=$user->select();
// dump($list);
// $user->modelTest();
//Three: Instantiate a user-defined model
//Mostly used for businesses that do not require more complexity
//1. Manually create a model and create a custom model for the user table, which can encapsulate the functions provided by thinkphp
//$user=new UserModel() is equivalent to D('user');
//D method will throw an exception if the model does not exist, and will only instance one instance. By default, it only supports calling the model under the current application
// $user=new UserModel();
// $list=$user->select();
// dump($list);
// $user->modelTest();
//4. Instantiate an empty model; it is the way of traditional sql statement; table prefix needs to be added
//
$user=new Model();
$list=$user->query('select * from tb_user');
dump($list);
//Group: D('admin.user');
}
}
?>
Two models:
[php]
class CommonModel extends Model{
function modelTest(){
Echo 'test cross -model operation, call the method in the model';
} }
}
?>
[php]
class UserModel extends Model{
function modelTest(){
Echo 'test cross -model operation, call the method in the model';
} }
}
?>
http://www.bkjia.com/PHPjc/477793.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/477793.htmlTechArticleCreate Action class [php] ?php class NewObjectAction extends Action{ public function index(){ //1. Create A basic model // //1: Instantiate a system database operation class // //new...
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
Latest Articles by Author
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31