Home >php教程 >PHP开发 >[ThinkPHP Series] The ThinkPHP framework enables web pages to be accessed in the browser (2)

[ThinkPHP Series] The ThinkPHP framework enables web pages to be accessed in the browser (2)

黄舟
黄舟Original
2016-12-28 10:37:162029browse

a) Place the web page template in the View view and create folders according to the names, and create them in modules
For example: the homepage is index.html, the news module has addNews.html, allNews.html, (the following contents are This example will be used). We can create such a directory structure:

|-View
| |-Index
| | |-index.html
| |-News
| | |-add.html(addNews.html)
| | |-all.html(allNews.html)

b) The Controller creates such a directory structure

|-Controller
| |-IndexController.class.php
| |-NewsController.class.php

c) Now that the directory structure is in place, we start typing the code.

IndexController.class.php
<?php
namespace Home\Controller;//命名空间
use Think\Controller;//使用Think目录中的核心函数
class IndexController extends Controller{
    public function index(){
        $this->display();//加载模板文件,让模板呈现在浏览器中
    }
}
?>
NewsController.class.php
<?php
namespace Home\Controller;
use Think\Controller;
class NewsController extends Controller{
    public function add(){
        $this->display();
    }
    public function all(){
        $this->display();
    }
}
?>

Okay, in this case, these pages can be displayed in the browser.

d) Understanding the address bar

1、localhost/app/ Home
    模块下的Index控制器index⽅法
2、localhost/app/index.php/Home/Index/lists:
    Home模块下的Index控制器lists方法
3、localhost/app/index.php/Home/News/add
    Home模块下的News控制器add方法
4、localhost/app/index.php/Home/News/edit/id/2

The above is the [ThinkPHP series] ThinkPHP framework enables web pages to be accessed in the browser (2). For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn