Dedecms:
The code is as follows: |
Copy code |
<Ul> {Dede: arclist row = '10' orderby = 'Id desc 'titlelen = ''} <Li> [field: title] </li> {/Dede: arclist} </Ul> Phpcms: <Ul> {Pc: content action = "hits" catid = "6" num = "10" order = "views DESC "} {Loop $ data $ r} <Li >{$ r [title]} </li> {/Loop} {/Pc} </Ul>
|
This is what makes them powerful. Next we will introduce THINKPHP's powerful TAG Extension Library. Thinkphp comes with a tag Extension Library. As long as we inherit TagLib, we can define our own tags as needed.
Naming rules: www.111cn.net
TagLib + tag library name. class. php
The following example shows how to call the navigation file name TagLibNav. class. php.
The code is as follows: |
Copy code |
<? Php Class TagLibNav extends TagLib { // Whether to close the attr attribute list (0 or 1 by default). alias tag alias level nested hierarchy // Tag definition Protected $ tags = array ( 'Nav' => array ('attr' => 'Limit, Order', 'level' => 3, 'close' => 1 ), ); // Define the query database tag www.111cn. Net // Attr is the attribute list and $ content stores the content between tags. Public function _ nav ($ attr, $ content ){ $ Tag = $ this-> parseXmlAttr ($ attr, $ content ); $ Cate = M ('channel '); $ Tb = $ cate-> order ($ tag ['order'])-> limit ($ tag ['limit'])-> select (); $ Str = ''; For ($ I = 0; $ I <count ($ tb); $ I ++) { $ C = str_replace (array ("[filed: id]", "[filed: name]"), array ($ tb [$ I] ['id'], $ tb [$ I] ['name']), $ content ); $ Str. = $ c; } Return $ str; } } ?> |
Html call method
The code is as follows: |
Copy code |
<TagLib name = "nav"/> // The header must be referenced. Otherwise, an error occurs. <Html> <Head> <Title> tablist </title> </Head> <Body> <Div class = "nav"> <Ul> <Li> homepage </li> <Nav: nav limit = '4' order = 'Id asc '> <Li> <a href = "[filed: id]"> [filed: name] </a> </li> </Nav: nav> </Ul> </Div> </Body> </Html>
|
Configuration file
'App _ AUTOLOAD_PATH '=>' @. TagLib ', // The location of TagLib @. Indicates the location in the current folder
'Taglib _ BUILD_IN '=> 'cx, Nav', // Cx is the name of the thinkphp Base Class Library, which must be referenced; otherwise, tags such as volist cannot be used, and Nav is the name of the custom label.
Controller
The code is as follows: |
Copy code |
<? Php Class IndexAction extends Action { Public function index (){ $ This-> display (); } } ?>
|
In this way, you don't need to write a lot of code in the controller !! Is it easy?