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)

黄舟
Release: 2016-12-28 10:37:16
Original
2021 people have browsed it

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)
Copy after login

b) The Controller creates such a directory structure

|-Controller
| |-IndexController.class.php
| |-NewsController.class.php
Copy after login

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();//加载模板文件,让模板呈现在浏览器中
    }
}
?>
Copy after login
NewsController.class.php
<?php
namespace Home\Controller;
use Think\Controller;
class NewsController extends Controller{
    public function add(){
        $this->display();
    }
    public function all(){
        $this->display();
    }
}
?>
Copy after login

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
Copy after login

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)!


Related labels:
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template