thinkphp Framework Trial

Source: Internet
Author: User

accidentally see thinkphp a PDF document, its outstanding characteristics are very attractive to me, so can't restrain the enthusiasm, download down familiar. Here is the simplest demo.

Steps:

Create a new web directory (I created a new Mydemo directory under the Web root directory), copy thinkphp directory!

New file index.php as portal file! The contents are 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 that defines the frame is in the thinkphp directory of the current directory, the name of the application is Hello, the directory is the current directory, of course, you can also put in the subdirectory, will not affect the final access address structure!

I use the 1.0.4 version, do not manually build the directory structure! As long as the entry file is defined, it will be generated automatically the first time it runs! This feature was added to the 1.0.2 version! More Convenient!

Open Browser, access address

See the CUE Message!

To illustrate, thinkphp's address structure is like this!

< Project entry file >/<moduleName>/<actionName>

If ModuleName and actionname are not specified, the index module and the index action are used by default (you can

Changes in the configuration file)

Thinkphp is based on the MVC architecture, and if you're not sure about MVC, get to know it first!

Try using the template again!

Let's take a look at the lib/action first. There is a IndexAction.class.php file, which is probably as follows:

<?php
class IndexAction extends Action{
public function index() {
//
}
}
?>

An index class that inherits from the action, which has an index function! (The index function is also the default action!) , and how to do it, steps as follows:

Create a new default folder under the TPL directory, and then create a new index.html file under Default, thinkphp using the template under defaults! The contents of the index.html file are as follows:

Program code

{$welcome _info}

For simplicity, I've only defined a label! And did not add THML code!

Then add the following code in 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 ();
}
}
?>

Replace the Welcome_info label assignment with "Hello world!" using assign, and the display function outputs the replacement result!

Once again, you can see the output as "Hello world!" and we want the result! Of course, the full access address should be like this:

Format: Entry file + module name + operation name

You can see the results of two addresses are consistent!

Thinkphp framework to fully consider the SEO, with support PDO, Ajax and many other features! Very worthwhile to learn and to use in practice! Of course, its code more based on PHP5, choose the time should pay attention!

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.