ThinkPHP learning notes (8) a small example of adding, deleting, modifying, and querying a user is mainly about how to implement the action File: conf file & lt ;? Php $ selfConfigarray (it is best to delete some ~ App. php and ~ Runtime. php configuration item & gt; the configuration value can be accessed through the original path, for example, ThinkPHP learning notes, because the URL is enabled again, whether it is overwritten or not. (8) A small example of adding, deleting, modifying, and querying users
The main method is to implement the action File:
Conf file
'Configuration value' // because the URL is enabled again, whether it is overwritten or not, it can be accessed through the original path. // If you want to enable the rewrite mode, perform the following operations // 1. the query server has enabled the Apache rewrite module // LoadModule rewrite_module modules/mod_rewrite.so // 2. create a new one under the statistics Directory of the master Portal file. htaccess (vi: save. htaccess; notepad :". htaccess ") // If you select mode 2 (rewrite), the server will consume more 'URL _ model' => 1, 'URL _ PATNINFO_MODEL '=> 2, // pathinfo contains two classes // 1 Normal mode: m and a: The order relationship can change // http: // localhost/MyThinkPHP/admin. php/m/index/a/index // pass the value // http: // localhost/MyThinkPHP/admin. php/m/index/a/index/username/zhangsan/password // 2 intelligent identification module operation (intelligent identification is the default mode) // http: // localhost/MyThinkPHP/admin. php/index // pass the value // http: // localhost/MyThinkPHP/admin. php/index/username/zhangsan/password // modify the URL separator // 'URL _ pathinfo_depr' => '-', // modify the left and right delimers of the template 'tmpl _ L_DELIM '=>'
', // ************************************ Very gorgeous split line ** *********************************** // enable debugging mode // 1. simulate a linux system to identify the case. // 2. the case sensitivity of the method name is related to the case sensitivity of the template file. // note: No body exists on the frame splitting page, however, the app_dubug information is the content in the body 'app _ debug' => true, // You can customize the Trace information of the page. // The Trace information of the configuration file path is configured in pageTrace under Thinkphp/Tpl. tpl. php // custom method: // 'tmpl _ TRACE_FILE '=> APP_PATH. '/Public/trace. php ', // or custom trace. put the php page in the current Conf folder // Default debugging file location: // ThinkPHP/Common/debug. php // do not cache database fields; If it is enabled, you can delete the files under Runtim/Data/'DB _ FIELDS_CACHE '=> false, // You can customize the debug. put php in the current Conf folder // Set APP_DEBUG to false and add the following parameter // 'app _ debug' => false, // Display running times the time required for this page // 'show _ RUN_TIME '=> true, // display the detailed running time (based on SHOW_RUN_TIME) // 'show _ ADV_TIME '=> true, // display the number of database operations (based on SHOW_RUN_TIME) // 'show _ DB_TIMES' => true, // display the number of cached operations (based on SHOW_RUN_TIME) // 'show _ CACHE_TIMES '=> true, // display the memory overhead (based on SHOW_RUN_TIME) // 'show _ USE_MEM '=> true, // set the template // 'Def AULT_THEME '=> 'default', // log processing class: lib/Think/Core/log. class. php // enable LOG // 'log _ RECORD '=> true, // log processing class: lib/Think/Core/log. class. php has a processing level, which can be selectively added // 'log _ RECORD_LEVEL '=> array ('error', 'Alert '), // because the connection to the database requires multiple projects, you can define a public configuration item in one page, returns an array // database connection settings // 'DB _ type' => 'mysql', // 'DB _ host' => 'localhost ', // 'DB _ name' => 'hibernate ', // 'DB _ user' => 'root', // 'DB _ pwd' => 'root ', /// if not modified, you do not need to enter // 'DB _ post' => '123', // 'DB _ PREF IX '=> 'TB _', // TOKEN-related operations // 'token _ on' => true, // 'token _ name' => '_ hash _', // 'token _ type' => 'md5',); $ databaseConfig = include '. /database. php '; // after the connection is returned, it is not easy to use. you can only directly return custom configuration information. it may be because of a problem with my configuration. leave this question first: return array_merge ($ selfConfig, $ databaseConfig); // return $ selfConfig;?>
Database link files and configurations introduced externally
1, // Database deployment method: 0 centralized (single server), 1 distributed (master-slave server) // 2. you must configure the database server // Baidu sets the database cluster // 3. read/write splitting (the first server is the write server by default, and the read server of other servers) // 'DB _ RW_SEPARATE '=> true, // whether the read/write operations of the database are separated from the master/slave mode. // The default character set of ThinkPHP is utf8. do not strip-// 'DB _ FIELDTYPE_CHECK '=> false, // whether to check the field type // 'DB _ FIELDS_CACHE '=> true, // enable the field cache // 'DB _ charset' => 'utf8 ', // The database encoding uses utf8 by default. // because the database link requires multiple projects, you can define public configuration items on one page, returns the db directory in the array // ThinkPHP: Lib/Think/Db. class. php // Set 'DB _ type' => 'mysql', 'DB _ host' => 'localhost' to connect to the database ', // when setting master/slave data, // 'DB _ host' => 'localhost, 192.168.123.1 ', 'DB _ name' => 'thinkphp ', // if the NAME of the master/slave data is different/'DB _ name' => 'hibernate, ant, thinkphp', 'DB _ user' => 'root ', 'db _ pwd' => 'root', // if not modified, you do not need to enter 'DB _ post' => '123 ', 'db _ prefix' => 'TB _ ',);?>
Action
Select (); $ this-> assign ('title', 'thinkphp Demo'); $ this-> assign ('alist', $ list ); $ this-> display ();} public function add () {// D requires some models, and M does not need to write $ user = D ('user '); if ($ vo = $ user-> create () {echo 'create successfully'; $ user-> password = md5 ($ user-> password ); $ user-> createtime = time (); // The extension function needs to use load ('extend') after loading; $ user-> createip = get_client_ip (); if ($ user-> add () {$ this-> success ("user registration successful ");} else {$ this-> error ($ user-> getError () ;}} else {Echo 'create failed'; $ this-> error ($ user-> getError () ;}} public function del () {// D requires some models, M does not need to write $ user = D ('user'); if ($ vo = $ User-> delete ($ _ GET ['id']) {$ this-> success ("user deleted successfully");} else {$ this-> error ($ user-> getError ();} public function edit () {$ user = M ('user'); $ id = $ _ GET ['id']; $ list = $ user-> where ("id = $ id ") -> find (); $ this-> assign ('user', $ list); $ this-> assign ('title', 'edit user '); $ this-> display ();} public function update () {$ User = M ('user'); if ($ vo = $ user-> create () {if ($ lineNum = $ user-> save ()) {$ this-> success ("user updated successfully");} else {$ this-> error ($ user-> getError ());}} else {$ this-> error ($ user-> getError () ;}}}?>
Model
Html:
Index.html
<! -- {$ Title} -->
ID
User name
IP
"> Delete"> Edit
Edit.html
<!--{$title}-->