Self-learning PHP environment build a plug-in. first install phpstudy2013.exe integrated package installation may be occupied Port needs to manually set the default username root password root II, build thinkphp framework first go to the http://www.thinkphp.cn to download the core package or complete package 1. in the root... "/> <scripttype =" text/java
Build a PHP environment
1. first install phpStudy2013.exe
After installing the program integration package, you must manually set the port to be occupied.
Default username root password root
II. build the thinkphp framework
Go to the http://www.thinkphp.cn to download the core package or complete package
1. create a project folder in the root directory, such as GuestBook_Think. copy ThinkPHP to it, create a folder named GuestBook for storing the project, and create a new php file index. php: defines the entry. the code is as follows:
[Php]
// Define the ThinkPHP path
Define ('think _ path', './ThinkPHP /');
// Define the project name
Define ('app _ name', 'guestbook ');
// Define the project path
Define ('app _ path', './GuestBook ');
// Load the entry file
Require (THINK_PATH. '/ThinkPHP. php ');
// Instantiate this project
$ App = new App ();
// Execute initialization
$ App-> run ();
?>
// Define the ThinkPHP path
Define ('think _ path', './ThinkPHP /');
// Define the project name
Define ('app _ name', 'guestbook ');
// Define the project path
Define ('app _ path', './GuestBook ');
// Load the entry file
Require (THINK_PATH. '/ThinkPHP. php ');
// Instantiate this project
$ App = new App ();
// Execute initialization
$ App-> run ();
?> Note:
Definition of the constant THINK_PATH:
ThinkPHP 2.x
Define ('think _ path', '../thinkphp ');
ThinkPHP 3.x
Define ('think _ path', '../ThinkPHP /');
If there are no other problems, smile and welcome to ThinkPHP!
2. create a config. php file under the conf folder (it should already exist and only needs to be modified). modify the configuration information as follows:
[Php]
If (! Defined ('think _ path') exit ();
Return array (
'Db _ type' => 'mysql', // The database used is mysql.
'Db _ host' => 'localhost ',
'Db _ name' => 'myguestbook', // database NAME
'Db _ user' => 'root ',
'Db _ pwd' => '', // enter your database connection password
'Db _ port' => '123 ',
'Db _ prefix' => 'think _ ', // table name PREFIX
);
?>
If (! Defined ('think _ path') exit ();
Return array (
'Db _ type' => 'mysql', // The database used is mysql.
'Db _ host' => 'localhost ',
'Db _ name' => 'myguestbook', // database NAME
'Db _ user' => 'root ',
'Db _ pwd' => '', // enter your database connection password
'Db _ port' => '123 ',
'Db _ prefix' => 'think _ ', // table name PREFIX
?>
3. create some php files in the Lib \ Model Directory, one-to-one correspondence with database tables
File name specification: table name + Model. class. php (without the think _ prefix)
For example, GuestBookInfoModel. class. php indicates that there is a table named guestbookinfo in the database.
The code in is as follows:
[Php]
Class GuestBookInfoModel extends Model {}
?>
Class GuestBookInfoModel extends Model {}
?>
4. next we should write the template and create the index.html file under \ Tpl \ default \ index. the template write method is similar to that of smarty. the code is as follows:
Some labels are defined in the static template and can be displayed by assigning values to the PHP file,
Basic label Definition Specification: {$ variable name}
5. assign a value to the variable in action. \ Lib \ Action \ for example, write the value assignment code in the IndexAction. class. php file.
[Php]
Class IndexAction extends Action {
Public function index (){
$ This-> assign ("title", "Test title ");
$ This-> assign ('name', "haha ");
$ This-> display ();
}
}
?>
Class IndexAction extends Action {
Public function index (){
$ This-> assign ("title", "Test title ");
$ This-> assign ('name', "haha ");
$ This-> display ();
}
}
?>