Home > Article > PHP Framework > How to render thinkphp5 public page
ThinkPHP5 is a powerful PHP development framework with the advantages of easy to learn, easy to use, efficient and stable. In the development model where the front and back ends are separated, the front end usually needs to introduce some public pages, such as the header, bottom, navigation bar, etc. So, how to render public pages in ThinkPHP5? Below I will introduce how to operate it.
1. Use the include statement
include is a function of PHP that can include the contents of the specified file into the current PHP file. Therefore, we can use the include statement to introduce the code of the public page where we need to render the public page. For example:
<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8"> <title>首页 - MyWeb</title> </head> <body> <?php include('header.html'); ?> <!-- 此处为页面内容 --> <?php include('footer.html'); ?> </body> </html>
In the above code, two public pages, header.html and footer.html, are introduced into the HTML file through the include statement.
2. Use template engine
ThinkPHP5 has a built-in PHP template engine, which can use template syntax when writing HTML code to separate front-end code and back-end code, improving development efficiency and Code maintainability. In the template engine, we can use the include tag to introduce public pages. For example:
<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8"> <title>首页 - MyWeb</title> </head> <body> {include file="header.html"} <!-- 此处为页面内容 --> {include file="footer.html"} </body> </html>
In the above code, {include file="header.html"}
and {include file="footer.html"}
are introduced respectively There are two public pages, header.html and footer.html.
Summary
The above are two common methods for rendering public pages in ThinkPHP5. The first method is suitable for simple scenarios and small projects; the second method is suitable for large projects and has better maintainability and scalability. More importantly, with the continuous development and advancement of front-end technology, we can use more tools and technologies to achieve front-end and back-end separation, improving development efficiency and user experience.
The above is the detailed content of How to render thinkphp5 public page. For more information, please follow other related articles on the PHP Chinese website!