Home>Article>PHP Framework> How to use templates in thinkphp

How to use templates in thinkphp

爱喝马黛茶的安东尼
爱喝马黛茶的安东尼 Original
2019-08-22 11:19:32 6729browse

How to use templates in thinkphp

First of all, you must go to the official website to download the thinkphp framework. Remember to select the thinkphp3.2.2 version, and then unzip it to the desktop or other disks. This is to make it easier for us to find it when using it.

How to use templates in thinkphp

How to use templates in thinkphp

Then open wampserver or other PHP service software, and then open zendstudio (other editors are also acceptable).

How to use templates in thinkphp

How to use templates in thinkphp

Related recommendations: "ThinkPHP Tutorial"

Create a php project, and then Find the folder where you created the project in the www directory, copy and paste the thinkphp file into it, and open the webpage to see if "Welcome to Thinkphp" appears, which means thinkphp is imported successfully.

How to use templates in thinkphp

How to use templates in thinkphp

Then go back to the editor and refresh the project folder. Thinkphp related folders will appear. Find the Application folder and open it. home file, this folder is mainly used to operate the front-end module.

How to use templates in thinkphp

How to use templates in thinkphp

When we open the web page and see the "Welcome to Thinkphp" content, it is controlled and displayed in the Controller class in the home folder. . So to make the template display, we need to change $this->show("..."); to $this->display(); . This is because when we refresh the web page, we will see that the template does not exist. This is because we have not imported the template yet.

How to use templates in thinkphp

How to use templates in thinkphp

At this time we can prompt to create an Index folder under the view folder, and then import the template we want to import, this When we refresh the page, we can see the template page we imported, but there is no style at this time.

How to use templates in thinkphp

How to use templates in thinkphp

Next we need to import the styles to make the page look better. Generally, we put the front-end template styles in the Public folder. , here we copy and paste the relevant styles of the previously imported template into the Public folder.

How to use templates in thinkphp

Simply putting these style files into the Public folder is not enough. We also need to add __PUBLIC__/ in front of the paths where js, cs, image, and these styles are imported. , so that the style can be imported correctly.

How to use templates in thinkphp

How to use templates in thinkphp

Finally refresh the page and we can see the web page template we want. Of course, sometimes the js, css, and style paths are not written properly. This will lead to some effects being impossible to achieve, and then everyone has to rely on themselves.

How to use templates in thinkphp

How to use templates in thinkphp

The above is the detailed content of How to use templates in thinkphp. For more information, please follow other related articles on the PHP Chinese website!

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