Thinkphp framework trial

Source: Internet
Author: User
I accidentally saw a PDF file of thinkphp, which attracted me very much with its excellent features. So I couldn't help the enthusiasm, So I downloaded it and got familiar with it. The following is the simplest demo.
Steps:
Create a new web directory (I created a mydemo directory under the web root directory) and copy the thinkphp directory here!
Create a new file index. php as the entry file! The content is as follows:

<? PHP
Define ('Think _ path', 'thinkphp ');
Define ('app _ name', 'Hello ');
Define ('app _ path ','.');
Require (think_path. "/thinkphp. php ");
$ APP = new app ();
$ App-> Run ();
?>

The Directory of the framework definition is in the thinkphp directory of the current directory. The application name is hello and the directory is the current directory. You can also put the directory in the subdirectory, the final access address structure will not be affected!
I am using version 1.0.4 and do not need to manually generate the directory structure! As long as the entry file is defined, it will be automatically generated during the first run! This feature was introduced in version 1.0.2! Convenient!
Open a browser and access the address
HTTP: /localhost: 8080/mydemo/index. php
The prompt message is displayed!
Note that thinkphp's address structure is like this!
Http: // <servername>/[<appname>]/<project portal File>/<modulename>/<actionname>
If modulename and actionname are not specified, the index module and index operation are used by default.
Changes in the configuration file)
Thinkphp is based on the MVC structure. If you are not clear about MVC, please first understand it!
Try the template again!
Let's take a look at lib/action first! There is an indexaction. Class. php file with the following content: <? PHP
Class indexaction extends action {
Public Function Index (){
//
}
}
?>

An index class inherited from action. There is an index function in it! (The index function is also the default action !), The procedure is as follows:
Create a new ultultfile folder under the tpl directory, and then create the index.html file under default. thinkphp uses the default template by default! The content of the index.html file is as follows: program code {$ welcome_info}

For simplicity, I have defined only one tag! Thml code is not added!
Then add the following code to the indexaction. Class. php file: program code <? PHP
Class indexaction extends action {
Public Function Index (){
Header ("Content-Type: text/html; charset = UTF-8 ");
$ This-> assign ("welcome_info", "Hello world! ");
$ This-> display ();
}
}
?>

Use assign to replace the welcome_info tag value with "Hello world! ", Display function output replacement result!
Access http: // localhost: 8080/mydemo/index. php again. The output content is "Hello world! ", The result we want! Of course, the complete access address should be like this:
HTTP: /localhost: 8080/mydemo/index. php
Format: entry file + Module name + operation name
The access results of the two addresses are consistent!
The thinkphp framework fully considers Seo and supports many features such as PDO and Ajax! It is worth learning and practical use! Of course, its code is more based on PhP5. Pay attention to it when selecting it!

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.