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>
将上面的代码命名为"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>
将上面的代码命名为"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>
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>
Smarty的功能很多很多(使用了半年,深有体会),还有待大家继续发掘。。。。

PHP ist eine serverseitige Skriptsprache, die für dynamische Webentwicklung und serverseitige Anwendungen verwendet wird. 1.PHP ist eine interpretierte Sprache, die keine Zusammenstellung erfordert und für die schnelle Entwicklung geeignet ist. 2. PHP -Code ist in HTML eingebettet, wodurch es einfach ist, Webseiten zu entwickeln. 3. PHP verarbeitet die serverseitige Logik, generiert die HTML-Ausgabe und unterstützt Benutzerinteraktion und Datenverarbeitung. 4. PHP kann mit der Datenbank interagieren, die Einreichung von Prozessformularen und serverseitige Aufgaben ausführen.

PHP hat das Netzwerk in den letzten Jahrzehnten geprägt und wird weiterhin eine wichtige Rolle bei der Webentwicklung spielen. 1) PHP stammt aus dem Jahr 1994 und ist aufgrund seiner Benutzerfreundlichkeit und der nahtlosen Integration in MySQL die erste Wahl für Entwickler. 2) Zu den Kernfunktionen gehört das Generieren dynamischer Inhalte und die Integration in die Datenbank, sodass die Website in Echtzeit aktualisiert und auf personalisierte Weise angezeigt wird. 3) Die breite Anwendung und das Ökosystem von PHP hat seine langfristigen Auswirkungen angetrieben, steht jedoch auch mit Versionsaktualisierungen und Sicherheitsherausforderungen gegenüber. 4) Leistungsverbesserungen in den letzten Jahren, wie die Veröffentlichung von PHP7, ermöglichen es ihm, mit modernen Sprachen zu konkurrieren. 5) In Zukunft muss PHP sich mit neuen Herausforderungen wie Containerisierung und Microservices befassen, aber seine Flexibilität und die aktive Community machen es anpassungsfähig.

Zu den Kernvorteilen von PHP gehören einfacher Lernen, starke Unterstützung für Webentwicklung, reiche Bibliotheken und Rahmenbedingungen, hohe Leistung und Skalierbarkeit, plattformübergreifende Kompatibilität und Kosteneffizienz. 1) leicht zu erlernen und zu bedienen, geeignet für Anfänger; 2) gute Integration in Webserver und unterstützt mehrere Datenbanken. 3) leistungsstarke Frameworks wie Laravel; 4) hohe Leistung kann durch Optimierung erzielt werden; 5) mehrere Betriebssysteme unterstützen; 6) Open Source, um die Entwicklungskosten zu senken.

PHP ist nicht tot. 1) Die PHP -Community löst aktiv Leistungs- und Sicherheitsprobleme, und Php7.x verbessert die Leistung. 2) PHP ist für die moderne Webentwicklung geeignet und wird in großen Websites häufig verwendet. 3) PHP ist leicht zu erlernen und der Server funktioniert gut, aber das Typsystem ist nicht so streng wie statische Sprachen. 4) PHP ist in den Bereichen Content-Management und E-Commerce immer noch wichtig, und das Ökosystem entwickelt sich weiter. 5) Optimieren Sie die Leistung über Opcache und APC und verwenden Sie OOP- und Designmuster, um die Codequalität zu verbessern.

PHP und Python haben ihre eigenen Vor- und Nachteile, und die Wahl hängt von den Projektanforderungen ab. 1) PHP eignet sich für Webentwicklung, leicht zu lernen, reichhaltige Community -Ressourcen, aber die Syntax ist nicht modern genug, und Leistung und Sicherheit müssen beachtet werden. 2) Python eignet sich für Datenwissenschaft und maschinelles Lernen mit prägnanter Syntax und leicht zu erlernen. Es gibt jedoch Engpässe bei der Ausführungsgeschwindigkeit und des Speichermanagements.

PHP wird verwendet, um dynamische Websites zu erstellen. Zu den Kernfunktionen gehören: 1. Dynamische Inhalte generieren und Webseiten in Echtzeit generieren, indem Sie eine Verbindung mit der Datenbank herstellen; 2. Verarbeiten Sie Benutzerinteraktions- und Formulareinreichungen, überprüfen Sie Eingaben und reagieren Sie auf Operationen. 3. Verwalten Sie Sitzungen und Benutzerauthentifizierung, um eine personalisierte Erfahrung zu bieten. 4. Optimieren Sie die Leistung und befolgen Sie die Best Practices, um die Effizienz und Sicherheit der Website zu verbessern.

PHP verwendet MySQLI- und PDO-Erweiterungen, um in Datenbankvorgängen und serverseitiger Logikverarbeitung zu interagieren und die serverseitige Logik durch Funktionen wie Sitzungsverwaltung zu verarbeiten. 1) Verwenden Sie MySQLI oder PDO, um eine Verbindung zur Datenbank herzustellen und SQL -Abfragen auszuführen. 2) Behandeln Sie HTTP -Anforderungen und Benutzerstatus über Sitzungsverwaltung und andere Funktionen. 3) Verwenden Sie Transaktionen, um die Atomizität von Datenbankvorgängen sicherzustellen. 4) Verhindern Sie die SQL -Injektion, verwenden Sie Ausnahmebehandlung und Schließen von Verbindungen zum Debuggen. 5) Optimieren Sie die Leistung durch Indexierung und Cache, schreiben Sie hochlesbarer Code und führen Sie die Fehlerbehandlung durch.

Die Verwendung von Vorverarbeitungsanweisungen und PDO in PHP kann SQL -Injektionsangriffe effektiv verhindern. 1) Verwenden Sie PDO, um eine Verbindung zur Datenbank herzustellen und den Fehlermodus festzulegen. 2) Erstellen Sie Vorverarbeitungsanweisungen über die Vorbereitungsmethode und übergeben Sie Daten mit Platzhaltern und führen Sie Methoden aus. 3) Abfrageergebnisse verarbeiten und die Sicherheit und Leistung des Codes sicherstellen.


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

MantisBT
Mantis ist ein einfach zu implementierendes webbasiertes Tool zur Fehlerverfolgung, das die Fehlerverfolgung von Produkten unterstützen soll. Es erfordert PHP, MySQL und einen Webserver. Schauen Sie sich unsere Demo- und Hosting-Services an.

SAP NetWeaver Server-Adapter für Eclipse
Integrieren Sie Eclipse mit dem SAP NetWeaver-Anwendungsserver.

VSCode Windows 64-Bit-Download
Ein kostenloser und leistungsstarker IDE-Editor von Microsoft

SublimeText3 Englische Version
Empfohlen: Win-Version, unterstützt Code-Eingabeaufforderungen!

ZendStudio 13.5.1 Mac
Leistungsstarke integrierte PHP-Entwicklungsumgebung