PHP environment build-PHP Tutorial-php Tutorial

Source: Internet
Author: User
Build a PHP environment by yourself. Build a PHP environment first. first install phpstudy2013.exe integrated package after installation may be occupied, you need to manually set the default user name root password 2. build thinkph self-built 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.thinkphp1.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 ();
}
}
?>


Tips 1. first install the phpStudy2013.exe integrated package. after installation, the port may be occupied. you need to manually set the default user name root password. 2. set thinkph...

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.