In ThinkPHP, the use of the Widget tool is very simple and convenient to call. Let's take calling hotspot articles as an example to describe how to use widgets. Because the wblog program is a common group, I will use the Widget tool in the ThinkPHP common group. Download wblog3.1.3 because wblog is installed, what databases and data tables are available, so you don't have to bother creating them. Creating widgets-related directories and files is easy to use and convenient to call in ThinkPHP. Let's take calling hotspot articles as an example to describe how to use widgets. Because the wblog program is a common group, I will use the Widget tool in the ThinkPHP common group.
Download wblog3.1.3
As wblog is installed, what databases and data tables are available, so you don't have to create them.
Create widgets related directories and files
Create related Widget directories and files according to the following directory structure.
├ ── W3note normal group project directory
│ ─ ── Common
│ ─ ── Conf
│ Mongo── Lang
├ ── Demo-lib
│ Processing-Action
│ Behavior-Behavior
│ ├ ── Model
│ ─ ── Widget
│ ├ ── Tpl implements ── HotWidget. class. php
│ Sampled-Hot
│ ├─Hot.html
Code of the HotWidget. class. php file
Field ('Id, title, hits ')-> order ('hits desc')-> limit (8)-> select (); return $ this-> renderFile ('', $ data) ;}}?>
Hot.html File Code
{$h['title']|msubstr=0,30,'utf-8'}
Call the Widget Tool
The call of the Widget tool is flexible and can be placed on the home page, list page, and content page. Next I will put it on the Content Page, open the W3note \ Tpl \ Read \ read.html file, and use {: W ('hot ')} to call the Widget tool we created above. The Code is as follows:
Hot articles
Final
Summary: In general, when we call a hotspot article, we need to create a statement in the Controller and then write a circular Statement on the template. However, this method is cumbersome to call on multiple pages, and the use of the Widget tool can easily solve this problem.