让你的Smarty更聪明_PHP
SMARTY
一、扩展你的Smarty1、准备功夫
<font size="2"><font face="Verdana">PHP代码:</font><hr></font><code><font color="#000000"> <font color="#0000bb"><br></font><font color="#007700">function </font><font color="#0000bb">Smarty_function_page </font><font color="#007700">( </font><font color="#0000bb">$params</font><font color="#007700">, &</font><font color="#0000bb">$Smarty </font><font color="#007700">) <br>{ <br> </font><font color="#0000bb">$href </font><font color="#007700">= </font><font color="#dd0000">'#'</font><font color="#007700">; <br> </font><font color="#0000bb">$space </font><font color="#007700">= </font><font color="#dd0000">' '</font><font color="#007700">; <br> <br> </font><font color="#0000bb">$frist </font><font color="#007700">= </font><font color="#0000bb">NULL</font><font color="#007700">; <br> </font><font color="#0000bb">$last </font><font color="#007700">= </font><font color="#0000bb">NULL</font><font color="#007700">; <br> <br> </font><font color="#0000bb">$page </font><font color="#007700">= </font><font color="#0000bb">5</font><font color="#007700">; <br> <br> </font><font color="#0000bb">extract</font><font color="#007700">(</font><font color="#0000bb">$params</font><font color="#007700">); <br> <br> if ( !</font><font color="#0000bb">$row </font><font color="#007700">|| </font><font color="#0000bb">$row </font><font color="#007700"><font color="#0000bb">1 </font><font color="#007700">) return </font><font color="#dd0000">' '</font><font color="#007700">; <br> <br> </font><font color="#0000bb">$pages </font><font color="#007700">= </font><font color="#0000bb">$row</font><font color="#007700">; <br> </font><font color="#0000bb">$curr_page </font><font color="#007700">= </font><font color="#0000bb">$now </font><font color="#007700">? </font><font color="#0000bb">$now </font><font color="#007700">: </font><font color="#0000bb">1</font><font color="#007700">; <br> </font><font color="#0000bb">$offset </font><font color="#007700">= </font><font color="#0000bb">2</font><font color="#007700">; <br> </font><font color="#0000bb">$from </font><font color="#007700">= </font><font color="#0000bb">$curr_page </font><font color="#007700">- </font><font color="#0000bb">$offset</font><font color="#007700">; <br> </font><font color="#0000bb">$to </font><font color="#007700">= </font><font color="#0000bb">$curr_page </font><font color="#007700">+ </font><font color="#0000bb">$page </font><font color="#007700">- </font><font color="#0000bb">$offset </font><font color="#007700">- </font><font color="#0000bb">1</font><font color="#007700">; <br> <br> if ( </font><font color="#0000bb">$page </font><font color="#007700">> </font><font color="#0000bb">$pages </font><font color="#007700">) <br> { <br> </font><font color="#0000bb">$from </font><font color="#007700">= </font><font color="#0000bb">1</font><font color="#007700">; <br> </font><font color="#0000bb">$to </font><font color="#007700">= </font><font color="#0000bb">$pages</font><font color="#007700">; <br> } <br> else <br> { <br> if ( </font><font color="#0000bb">$from </font><font color="#007700"><font color="#0000bb">1</font><font color="#007700">) <br> { <br> </font><font color="#0000bb">$to </font><font color="#007700">= </font><font color="#0000bb">$curr_page </font><font color="#007700">+ </font><font color="#0000bb">1 </font><font color="#007700">- </font><font color="#0000bb">$from</font><font color="#007700">; <br> </font><font color="#0000bb">$from </font><font color="#007700">= </font><font color="#0000bb">1</font><font color="#007700">; <br> if ( ( </font><font color="#0000bb">$to </font><font color="#007700">- </font><font color="#0000bb">$from </font><font color="#007700">) <font color="#0000bb">$page </font><font color="#007700">&& ( </font><font color="#0000bb">$to </font><font color="#007700">- </font><font color="#0000bb">$from </font><font color="#007700">) <font color="#0000bb">$pages </font><font color="#007700">) <br> { <br> </font><font color="#0000bb">$to </font><font color="#007700">= </font><font color="#0000bb">$page</font><font color="#007700">; <br> } <br> } <br> elseif ( </font><font color="#0000bb">$to </font><font color="#007700">> </font><font color="#0000bb">$pages </font><font color="#007700">) <br> { <br> </font><font color="#0000bb">$from </font><font color="#007700">= </font><font color="#0000bb">$curr_page </font><font color="#007700">- </font><font color="#0000bb">$pages </font><font color="#007700">+ </font><font color="#0000bb">$to</font><font color="#007700">; <br> </font><font color="#0000bb">$to </font><font color="#007700">= </font><font color="#0000bb">$pages</font><font color="#007700">; <br> if ( ( </font><font color="#0000bb">$to </font><font color="#007700">- </font><font color="#0000bb">$from </font><font color="#007700">) <font color="#0000bb">$page </font><font color="#007700">&& ( </font><font color="#0000bb">$to </font><font color="#007700">- </font><font color="#0000bb">$from</font><font color="#007700">) <font color="#0000bb">$pages </font><font color="#007700">) <br> { <br> </font><font color="#0000bb">$from </font><font color="#007700">= </font><font color="#0000bb">$pages </font><font color="#007700">- </font><font color="#0000bb">$page </font><font color="#007700">+ </font><font color="#0000bb">1</font><font color="#007700">; <br> } <br> } <br> } <br> <br> if ( </font><font color="#0000bb">$frist </font><font color="#007700">&& ( </font><font color="#0000bb">$curr_page </font><font color="#007700">- </font><font color="#0000bb">1 </font><font color="#007700">) >= </font><font color="#0000bb">1 </font><font color="#007700">) </font><font color="#0000bb">$p</font><font color="#007700">[</font><font color="#dd0000">'frist'</font><font color="#007700">] = </font><font color="#dd0000">'<a href="'%20</font><font%20color=">. </a></font><font color="#0000bb">$href </font><font color="#007700">. </font><font color="#dd0000">'1">' </font><font color="#007700">. </font><font color="#0000bb">$frist </font><font color="#007700">. </font><font color="#dd0000">''</font><font color="#007700">; <br> if ( </font><font color="#0000bb">$prev </font><font color="#007700">&& ( </font><font color="#0000bb">$i </font><font color="#007700">= </font><font color="#0000bb">$curr_page </font><font color="#007700">- </font><font color="#0000bb">1 </font><font color="#007700">) >= </font><font color="#0000bb">1 </font><font color="#007700">) </font><font color="#0000bb">$p</font><font color="#007700">[</font><font color="#dd0000">'prev'</font><font color="#007700">] = </font><font color="#dd0000">'<a href="'%20</font><font%20color=">. </a></font><font color="#0000bb">$href </font><font color="#007700">. </font><font color="#0000bb">$i </font><font color="#007700">. </font><font color="#dd0000">'">' </font><font color="#007700">. </font><font color="#0000bb">$prev </font><font color="#007700">. </font><font color="#dd0000">''</font><font color="#007700">; <br> for( </font><font color="#0000bb">$i </font><font color="#007700">= </font><font color="#0000bb">$from</font><font color="#007700">; </font><font color="#0000bb">$i </font><font color="#007700"><font color="#0000bb">$to</font><font color="#007700">; </font><font color="#0000bb">$i </font><font color="#007700">++ ) <br> { <br> if ( </font><font color="#0000bb">$i </font><font color="#007700">== </font><font color="#0000bb">$curr_page </font><font color="#007700">) <br> { <br> </font><font color="#0000bb">$p</font><font color="#007700">[</font><font color="#0000bb">$i</font><font color="#007700">] = </font><font color="#dd0000">'<a href="'%20</font><font%20color=">. </a></font><font color="#0000bb">$href </font><font color="#007700">. </font><font color="#0000bb">$i </font><font color="#007700">. </font><font color="#dd0000">'" class="nowpage" target="_self">[' </font><font color="#007700">. </font><font color="#0000bb">$i </font><font color="#007700">. </font><font color="#dd0000">']'</font><font color="#007700">; <br> } <br> else <br> { <br> </font><font color="#0000bb">$p</font><font color="#007700">[</font><font color="#0000bb">$i</font><font color="#007700">] = </font><font color="#dd0000">'<a href="'%20</font><font%20color=">. </a></font><font color="#0000bb">$href </font><font color="#007700">. </font><font color="#0000bb">$i </font><font color="#007700">. </font><font color="#dd0000">'" target="_self">' </font><font color="#007700">. </font><font color="#0000bb">$i </font><font color="#007700">. </font><font color="#dd0000">''</font><font color="#007700">; <br> } <br> } <br> if ( </font><font color="#0000bb">$next </font><font color="#007700">&& ( </font><font color="#0000bb">$i </font><font color="#007700">= </font><font color="#0000bb">$curr_page </font><font color="#007700">+ </font><font color="#0000bb">1 </font><font color="#007700">) <font color="#0000bb">$pages </font><font color="#007700">) </font><font color="#0000bb">$p</font><font color="#007700">[</font><font color="#dd0000">'next'</font><font color="#007700">] = </font><font color="#dd0000">'<a href="'%20</font><font%20color=">. </a></font><font color="#0000bb">$href </font><font color="#007700">. </font><font color="#0000bb">$i </font><font color="#007700">. </font><font color="#dd0000">'" target="_self">' </font><font color="#007700">. </font><font color="#0000bb">$next </font><font color="#007700">. </font><font color="#dd0000">''</font><font color="#007700">; <br> if ( </font><font color="#0000bb">$last </font><font color="#007700">&& ( </font><font color="#0000bb">$curr_page </font><font color="#007700">+ </font><font color="#0000bb">1 </font><font color="#007700">) <font color="#0000bb">$pages </font><font color="#007700">) </font><font color="#0000bb">$p</font><font color="#007700">[</font><font color="#dd0000">'last'</font><font color="#007700">] = </font><font color="#dd0000">'<a href="'%20</font><font%20color=">. </a></font><font color="#0000bb">$href </font><font color="#007700">. </font><font color="#0000bb">$pages </font><font color="#007700">. </font><font color="#dd0000">'" target="_self">' </font><font color="#007700">. </font><font color="#0000bb">$last </font><font color="#007700">. </font><font color="#dd0000">''</font><font color="#007700">; <br> <br> return </font><font color="#0000bb">implode</font><font color="#007700">( </font><font color="#0000bb">$space</font><font color="#007700">, </font><font color="#0000bb">$p </font><font color="#007700">); <br>} </font><font color="#ff8000">// end func<br></font><font color="#0000bb"></font> </font> </font></font></font></font></font></font></font></font></font></code><hr>Nach dem Login kopieren
将上面的代码命名为"function.page.php"保存到Smarty的plugins目录里
<font size="2"><font face="verdana,arial,helvetica">代码:</font><hr></font> <title> New Document </title> <meta name="Generator" content="EditPlus"> <meta name="Author" content=""> <meta name="Keywords" content=""> <meta name="Description" content=""> {page row=10} {page row=10 now=5} {page row=10 now=5 href="plugins.php?a=1&b=2&page=" frist="第一页" prev="上一页" next="下一页" last="最后页"} {page row=10 now=5 href="plugins.php?a=1&b=2&page=" frist="第一页" prev="上一页" next="下一页" last="最后页"} {page row=10 now=1 href="plugins.php?a=1&b=2&page=" frist="第一页" prev="上一页" next="下一页" last="最后页"} {page row=10 now=10 href="plugins.php?a=1&b=2&page=" frist="第一页" prev="上一页" next="下一页" last="最后页"} <hr>Nach dem Login kopieren
将上面的代码命名为"plugins.html"保存到Smarty的template目录里
2、测试程序
<font size="2"><font face="verdana,arial,helvetica">PHP代码:</font><hr></font><code><font color="#000000"> <font color="#0000bb"><br>$Smarty</font><font color="#007700">-></font><font color="#0000bb">display</font><font color="#007700">( </font><font color="#dd0000">'plugins.html' </font><font color="#007700">);<br></font><font color="#0000bb"></font> </font> </code><hr>Nach dem Login kopieren
3、使用说明
我懒得打了,对比一下"plugins.html"的5个{page}用法,以及看看显示出来的效果就明白是什么了
4、插件说明
“《Smarty手册》第十六章.以插件扩展Smarty ”的应用。像中文字符截取之类的都可以以plugins扩展Smarty,Smarty自带的截取不支持中文。
二、Smarty自动生成静态页面
如果你的文件扩展名为".html"~~~~~嘿嘿,这不就是静态页面了吗?-_-!
至于怎么取得静态的文件名呢?
<font size="2"><font face="verdana,arial,helvetica">PHP代码:</font><hr></font><code><font color="#000000"> <font color="#0000bb"><br></font><font color="#ff8000">/** <br> * <br> */ <br></font><font color="#007700">class </font><font color="#0000bb">template </font><font color="#007700">extends </font><font color="#0000bb">Smarty <br></font><font color="#007700">{ <br> <br> </font><font color="#ff8000">/** <br> * <br> */ <br> </font><font color="#007700">function </font><font color="#0000bb">template </font><font color="#007700">() <br> { <br> </font><font color="#0000bb">$this</font><font color="#007700">-></font><font color="#0000bb">Smarty</font><font color="#007700">(); <br> } </font><font color="#ff8000">// end func <br> <br> /** <br> * <br> */ <br> </font><font color="#007700">function </font><font color="#0000bb">name </font><font color="#007700">( </font><font color="#0000bb">$tpl_file</font><font color="#007700">, </font><font color="#0000bb">$cache_id </font><font color="#007700">= </font><font color="#0000bb">null</font><font color="#007700">, </font><font color="#0000bb">$compile_id </font><font color="#007700">= </font><font color="#0000bb">null </font><font color="#007700">) <br> { <br> <br> if (!isset(</font><font color="#0000bb">$compile_id</font><font color="#007700">)) </font><font color="#0000bb">$compile_id </font><font color="#007700">= </font><font color="#0000bb">$this</font><font color="#007700">-></font><font color="#0000bb">compile_id</font><font color="#007700">; <br> <br> </font><font color="#0000bb">$_auto_id </font><font color="#007700">= </font><font color="#0000bb">$this</font><font color="#007700">-></font><font color="#0000bb">_get_auto_id</font><font color="#007700">( </font><font color="#0000bb">$cache_id</font><font color="#007700">, </font><font color="#0000bb">$compile_id </font><font color="#007700">); <br> </font><font color="#0000bb">$_cache_file </font><font color="#007700">= </font><font color="#0000bb">$this</font><font color="#007700">-></font><font color="#0000bb">_get_auto_filename</font><font color="#007700">( </font><font color="#0000bb">$this</font><font color="#007700">-></font><font color="#0000bb">cache_dir</font><font color="#007700">, </font><font color="#0000bb">$tpl_file</font><font color="#007700">, </font><font color="#0000bb">$_auto_id </font><font color="#007700">); <br> <br> return </font><font color="#0000bb">basename</font><font color="#007700">( </font><font color="#0000bb">$_cache_file </font><font color="#007700">); <br> } </font><font color="#ff8000">// end func <br></font><font color="#007700">} </font><font color="#ff8000">// end class <br> <br></font><font color="#0000bb">$Smarty </font><font color="#007700">= new </font><font color="#0000bb">template</font><font color="#007700">; <br></font><font color="#0000bb">$file_name </font><font color="#007700">= </font><font color="#0000bb">$Smarty</font><font color="#007700">-></font><font color="#0000bb">name</font><font color="#007700">( </font><font color="#dd0000">'plugins.html'</font><font color="#007700">, </font><font color="#dd0000">'cache_name' </font><font color="#007700">);</font><font color="#ff8000">#html文件的名字(不包含路径) <br> <br></font><font color="#0000bb">$Smarty</font><font color="#007700">-></font><font color="#0000bb">cache_lifetime </font><font color="#007700">= -</font><font color="#0000bb">1</font><font color="#007700">;</font><font color="#ff8000">#静态文件永不过期 <br></font><font color="#0000bb">$Smarty</font><font color="#007700">-></font><font color="#0000bb">fetch</font><font color="#007700">( </font><font color="#dd0000">'plugins.html'</font><font color="#007700">, </font><font color="#dd0000">'cache_name' </font><font color="#007700">);</font><font color="#ff8000">#生成静态html文件<br></font><font color="#0000bb"></font> </font> </code><hr>Nach dem Login kopieren
Smarty的功能很多很多(使用了半年,深有体会),还有待大家继续发掘。。。。

Heiße KI -Werkzeuge

Undresser.AI Undress
KI-gestützte App zum Erstellen realistischer Aktfotos

AI Clothes Remover
Online-KI-Tool zum Entfernen von Kleidung aus Fotos.

Undress AI Tool
Ausziehbilder kostenlos

Clothoff.io
KI-Kleiderentferner

AI Hentai Generator
Erstellen Sie kostenlos Ai Hentai.

Heißer Artikel

Heiße Werkzeuge

Notepad++7.3.1
Einfach zu bedienender und kostenloser Code-Editor

SublimeText3 chinesische Version
Chinesische Version, sehr einfach zu bedienen

Senden Sie Studio 13.0.1
Leistungsstarke integrierte PHP-Entwicklungsumgebung

Dreamweaver CS6
Visuelle Webentwicklungstools

SublimeText3 Mac-Version
Codebearbeitungssoftware auf Gottesniveau (SublimeText3)

Heiße Themen



src und href sind jeweils 1. src ist die Abkürzung für Quelle, die zur Angabe des Pfads externer Ressourcen verwendet wird. Es wird normalerweise zum Einbetten externer Dateien wie Bilder, Audios, Videos usw. verwendet. Das src-Attribut ist im Allgemeinen wird für img, script, iframe und andere Tags verwendet. 2. href ist die Abkürzung für Hypertext-Referenz, die verwendet wird, um den Pfad der Zielressource des Hyperlinks anzugeben. Das href-Attribut wird im Allgemeinen für Tags wie a und link verwendet.

Implementieren von Daten-Paging und Anzeigeoptimierung in Vue-Projekten: Wenn eine Seite eine große Datenmenge anzeigen muss, muss in der Regel eine Daten-Paging- und Anzeigeoptimierung durchgeführt werden, um die Benutzererfahrung zu verbessern Implementieren Sie Daten-Paging und Anzeigeoptimierung und stellen Sie spezifische Codebeispiele bereit. 1. Daten-Paging Unter Daten-Paging versteht man die Aufteilung einer großen Datenmenge auf mehrere Seiten nach bestimmten Regeln und deren Anzeige auf der Seite. Mit den folgenden Schritten können Sie Daten-Paging in einem Vue-Projekt implementieren: Definieren Sie die Datenquelle. Definieren Sie zunächst eine Datenquelle, die alle Daten enthält.

Das src-Attribut und das href-Attribut sind häufig verwendete Attribute in HTML und werden zum Laden externer Ressourcen verwendet. Obwohl sie ähnliche Zwecke verfolgen, gibt es einige Unterschiede in der Verwendung und dem Zweck. src-Attribut: Das src-Attribut wird verwendet, um externe Ressourcen anzugeben, die in das Dokument eingebettet werden sollen. Es wird hauptsächlich zum Einfügen externer Skriptdateien und Mediendateien in HTML-Dokumente verwendet. Es kann in den folgenden Situationen verwendet werden: Externe JavaScript-Dateien einführen: Verknüpfen Sie externe JavaScript-Dateien über das src-Attribut mit HTML-Seiten.

Heutzutage ist die Website-Entwicklung untrennbar mit einer wichtigen Komponenten-Template-Engine verbunden. Eine Template-Engine bezieht sich auf ein Tool, das Seitenvorlagen und Daten kombiniert, um HTML-Code mit einem bestimmten Format zu generieren. In verschiedenen Website-Entwicklungsframeworks ist die Template-Engine eine wesentliche Komponente, da die Template-Engine die Duplizierung von Code erheblich reduzieren und die Dynamik der Seite verbessern kann. Eine der gebräuchlichsten und beliebtesten Template-Engines ist Smarty. Smarty ist ein DSL (DomainSpecif

In der modernen Webentwicklung ist die Trennung von Front-End und Back-End zu einem sehr beliebten Trend geworden, der es Entwicklern ermöglicht, Projekte besser zu organisieren und die Effizienz der Projektentwicklung zu verbessern. PHP und Smarty sind zwei sehr häufig verwendete Technologien, mit denen eine Front-End- und Back-End-Trennungsentwicklung erreicht werden kann. In diesem Artikel wird erläutert, wie Sie mit PHP und Smarty eine Front-End- und Back-End-Trennungsentwicklung erreichen. Was ist Front-End- und Back-End-Trennung? Bei der traditionellen Webentwicklung ist das Front-End hauptsächlich für die Darstellung der Seite und die Logik der Interaktion mit dem Back-End verantwortlich. Das Backend ist hauptsächlich für das Geschäft verantwortlich

Erhalten Sie von href und src gesendete Anfragen. Detaillierte Beschreibung: 1. Das href-Attribut wird verwendet, um die Zielressource des Links anzugeben. Beim Verweisen auf ein externes Stylesheet wird eine GET-Anfrage gesendet, um die CSS-Datei abzurufen Beim Verweisen auf ein Bild wird eine GET-Anfrage gesendet. Um die angegebene Bilddatei abzurufen, wird das src-Attribut verwendet, um die URL der eingebetteten Ressource anzugeben GET-Anfrage zum Abrufen der angegebenen Bilddatei Beim Verweisen auf das Audio wird eine GET-Anfrage gesendet, um die angegebene Audiodatei usw. abzurufen.

Hallo, es folgt ein Artikel mit 1500 Wörtern und dem Titel: Youcan'tspecifytargettable'table_name'forupdateinFROMclause – So beheben Sie den MySQL-Fehler: Die Zieltabelle kann in der FROM-Klausel nicht aktualisiert werden. Es sind spezifische Codebeispiele erforderlich. Während der Entwicklung einer MySQL-Datenbank stoßen wir manchmal auf die folgende Fehlermeldung: Youcan'tspecify

Der Unterschied zwischen src und href, Details, die Sie kennen müssen! Beim Schreiben von HTML-Seiten stoßen wir häufig auf die beiden Attribute src und href. Sie alle werden verwendet, um auf externe Ressourcen wie Skriptdateien, Stildateien oder Bilder zu verweisen. Obwohl ihre Zwecke ähnlich sind, gibt es einige Unterschiede in ihrer spezifischen Verwendung und ihren Details. Zunächst wird das src-Attribut (Quelle) hauptsächlich zum Einbetten externer Ressourcen wie Bilder oder Skripte verwendet. Es wird verwendet, um die Adresse einer Ressource anzugeben und ihren Inhalt in das aktuelle Dokument einzubetten. Und href(
