Here we need to configure two items, as mentioned in 1st City Notes 2, to remove/index. php/, and 2nd configuration items to prepare for database ING.
ThinkPHP study notes
Configure ThinkPHP
Here we need to configure two items, as mentioned in 1st City Notes 2, to remove/index. php/, and 2nd configuration items to prepare for database ING.
Configuration 1: Remove index. php from the URL
Remove the index. php entry file in the URL so that the URL is in the form of http: // 127.0.0.1/Index/index.
1. open the Myapp/Conf/config. php file and add a line to the configuration array:
'URL _ model' => 2,
2. create a new. htaccess file in the same directory as the entry file. the content is
. C>
RewriteEngineon
RewriteCond % {REQUEST_FILENAME }! -D
RewriteCond % {REQUEST_FILENAME }! -F
RewriteRule ^ (. *) $ index. php/$1 [QSA, PT, L]
Configuration 2: database ing
Open the/Myapp/Conf/config. php file and add the following content:
'App _ debug' => true, // enable the debugging mode
'Db _ type' => 'mysql', // Database TYPE
'Db _ host' => 'localhost', // address of the database server
'Db _ name' => 'test', // database NAME
'Db _ user' => 'root', // database username
'Db _ pwd' => '', // database password
'Db _ port' => '123', // database PORT
'Db _ prefix' => 'think _ ', // data table PREFIX
Interestingly, the last item, 'DB _ prefix' => 'think _ ', // The Data Table PREFIX framework has a convention, after the data table prefix attribute is specified in the configuration file, the built-in data access function is called during data access processing and the name after the data table prefix is passed. Data ING is automatically performed.
For example, in the database test, there is a data table named think_demo and think_test, in the form of $ form = D ('demo')-> findall, you can directly obtain all the data in think_demo. you can also use $ form = D ('test')-> findall (); to obtain all the data in the think_test table. It's very convenient!
4. test Horn:
Display all data in think_demo in database demo on the webpage
First of all, I have created a database named test and a table named think_demo in my MySQL database, and the data has been written into it.
Open the automatically generated file IndexAction. class. php (Lib \ Action) and create a new method named show.
Publicfunctionshow ()
{
// Set the character set to prevent garbled characters
Header ("Content-Type: text/html; charset = utf-8 ");
// Obtain all data in the table
$ Form = D ('demo')-> findall ();
Dump ($ form );
Exit;
}
Save and open the browser and enter http: // 127.0.0.1/myapp2/Index/show to see the result.
Here, by the way:
1. Why is it written in IndexAction. class. php? if I want to differentiate the application, can I write it somewhere else?
Writing in IndexAction. class. php is convenient, because it is a file automatically generated and some other things are generated. this is done to facilitate demonstration.
If you want to write it elsewhere, you can copy IndexAction. class. php and copy it to the same directory (Lib/Action ). Name according to the standard: name + Action. class. php, and then oh. For example, ShowAciton. class. php-> access: http: // 127.0.0.1/myapp2/Show/show
2. the browser's inbound force is case insensitive, that is, the Index/show and index/show are the same.