<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                <table cellspacing="0" cellpadding="0" width="100%" summary="Header navigation table" border="0"><tbody><tr><th align="middle" colspan="3">Smarty - the compiling PHP template engine<br/><br/> Smarty - PHP 模板編譯引擎</th></tr><tr><td valign="bottom" align="left" width="25%"><a accesskey="P" href="index.html">Prev</a></td> <td valign="bottom" align="middle" width="50%"/> <td valign="bottom" align="right" width="25%"><a accesskey="N" href="opinion.html">Next</a></td></tr></tbody></table> # Preface 序 **The Philosophy** The Smarty design was largely driven by these goals: ◆ clean separation of presentation from application code ◆ PHP backend, Smarty template frontend ◆ compliment PHP, not replace it ◆ fast development/deployment for programmers and designers ◆ quick and easy to maintain ◆ syntax easy to understand, no PHP knowledge necessary ◆ flexibility for custom development ◆ security: insulation from PHP ◆ free, open source **What is Smarty? **Smarty is PHP a framework for separating presentation (HTML/CSS) from application logic (PHP). This implies that PHP code is application logic, and is separated from the presentation. **Two camps of thought **When it comes to templating in PHP, there are basically two camps of thought. The first camp exclaims that "PHP is a template engine". Simply because PHP can mix with presentation doesn't mean it's a preferable choice. The only virtue to this approach is speed from a pure script-execution point of view. However, the PHP syntax is quite ugly and doesn't mix well with tagged markup such as HTML. The second camp exclaims that presentation should be void of all programming code, and instead use simple tags to indicate where application content is revealed. This approach is common with other development languages, and is also the approach that Smarty takes. The idea is to keep the templates focused squarely on presentation, not application code, and with as little overhead as possible. **Why is separating PHP from templates important? **Two major benefits: ◆ SYNTAX: Templates typically consist of semantic markup such as HTML. PHP syntax works well for application code, but quickly degenerates when mixed with HTML. Smarty's simple {tag} syntax is designed specifically to express presentation.Smarty focuses your templates on presentation and less on "code". This lends to quicker template deployment and easier maintenance. Smarty syntax requires no working knowledge of PHP, and is intuitive for programmers and non-programmers alike. ◆ INSULATION: When PHP is mixed with templates, there are no restrictions on what type of logic can be injected into atemplate. Smarty insulates the templates from PHP, creating a controlled separation of presentation from business logic.Smarty also has security features that can further enforce restrictions on templates. **Web designers and PHP ** A common question: "Web designers have to learn a syntax anyways, why not PHP?". Of course web designers can learn PHP, but this isn't about their ability to learn it. They learn PHP, then start stuffing things into templates that don't belong there (you just handed them a swiss-army knife when they just needed a knife.) You can teach them the rules of application development, but then you may as well call them developers. Smarty gives web designers exactly the tools they need, and gives developers fine-grained control over those tools. **Implementation is Important ** A common problem with Smarty development is poor implementation. If you abuse Smarty fundamentals or come across an application that does (i.e. injecting PHP in templates), you may end up with something worse than what Smarty was intended to resolve. See the Best Practices section on the Smarty website for examples of what to look out for. **How does it work? ** Under the hood, Smarty "compiles" (basically copies and converts) the templates into PHP scripts. This happens once when each template is first invoked, and then the compiled versions are used from that point forward. Smarty takes care of this for you, so the template designer just edits the Smarty templates and never has to manage the compiled versions. This approach keeps the templates easy to maintain, and yet keeps execution times extremely fast since the compiled code is just PHP. And of course, all PHP scripts take advantage of PHP op-code caches such as APC. **Template Inheritance ** Template inheritance is new to Smarty 3, and it's one of many great new features. Before template inheritance, we managed our templates in pieces such as header and footer templates. This organization lends itself to many problems that require some hoop-jumping, such as managing content within the header/footer on a per-page basis. With template inheritance, instead of including other templates we maintain our templates as single pages. We can then manipulate blocks of content within by inheriting them. This makes templates intuitive, efficient and easy to manage. See the Template Inheritance section of the Smarty website for more info. **Why not use XML/XSLT syntax? ** There are a couple of good reasons. First, Smarty can be used for more than just XML/HTML based templates, such as generating emails, javascript, CSV, and PDF documents. Second, XML/XSLT syntax is even more verbose and fragile than PHP code! It is perfect for computers, but horrible for humans. Smarty is about being easy to read, understand and maintain. **Template Security ** Although Smarty insulates you from PHP, you still have the option to use it in certain ways if you wish.Template security forces the restriction of PHP (and select Smarty functions.) This is useful if you have third parties editing templates, and you don't want to unleash the full power of PHP or Smarty to them. **Integration 整合** Sometimes Smarty gets compared to Model-View-Controller (MVC) frameworks. Smarty is not an MVC,it is just the presentation layer, much like the View (V) part of an MVC. As a matter of fact, Smarty can easily be integrated as the view layer of an MVC. Many of the more popular ones have integration instructions for Smarty, or you may find some help here in the forums and documentation. **Other Template Engines ** Smarty is not the only engine following the "Separate Programming Code from Presentation" philosophy.For instance, some Python developers decided that mixing Python with HTML/CSS wasn't such a great idea, and built some template engines around the same principles such as Django Templates and CheetahTemplate. **What Smarty is Not Smarty不是什么** Smarty is not meant to be a stand-alone tool for developing websites from scratch. Smarty is a tool to facilitate the presentation layer of your application. You may decide to use an existing framework with Smarty, or you might build your own codebase and use Smarty for the frontend. Either way, Smarty is a great way to decouple presentation from your application code. **Summary ** Whether you are using Smarty for a small website or massive enterprise solution, it can accommodate your needs. There are umerous features that make Smarty a great choice: ◆ separation of PHP from HTML/CSS just makes sense ◆ readability for organization and management ◆ security for 3rd party template access ◆ feature completeness, and easily extendable to your own needs ◆ massive user base, Smarty is here to stay ◆ LGPL license for commercial use ◆ 100% free to use, open source project **Should I use Smarty? ** Smarty's long track record has indicated that it significantly improves the speed of deployment and maintenance of templates. If maintenance is crucial to your application (or business), Smarty is certainly a good fit.However, Smarty is not a magic bullet. It is a tool for managing presentation. Using Smarty, another template engine, or plain PHP is largely going to be determined by your own requirements and tastes. It is certainly possible to maintain presentation mixed with PHP if you are happy with that. You may not have a need for Smarty if you don't need cleaner template syntax, template inheritance, caching, plugins,security (i.e. insulation from PHP), quicker presentational deployment and easier maintenance. The best approach is to ask lots of questions, install and test Smarty for yourself and make an informed decision for your project. **設計理念** Smarty主要為這些目標所驅動設計: ◆ 拋棄應用程序中php與其它語言雜揉的描述方式,使之統一樣式 ◆ php負責后臺,Smarty模版負責前端 ◆ 向php致意,而不是取代它 ◆ 程序員、美工能夠快速開發部署 ◆ 快速和易于維護 ◆ 語法簡單、容易理解,不必具備php知識 ◆ 客戶在開發中富有彈性 ◆ 安全:從php獨立出來 ◆ 免費,開源 ** Smarty是什么?** Smarty是一種從程序邏輯層(php)抽出外在(html/css)描述的PHP框架,這意味著php代碼只負責邏輯應用,從外在描述中分離了出來。 ** 兩種陣營的思考** 當提到php模版,就存在兩種陣營的思想。第一陣營的人大聲叫道“php本身就是一種模版引擎”。僅僅因為PHP能混合描述并不意味著這是個好的選擇,唯一的優點是純粹的腳本運行速度快。然而,php語法非常丑陋,根本不能與諸如html的標簽語法結合得很好。 第二陣營的人叫道,所有程序代碼(包括php等)不應描述外在表現,取而代之的是用簡單標簽指明在哪里顯示應用程序的內容,這種做法在其它語言中很常見,這也是Smarty所推崇的。它(Smarty)的思想是讓模版直接專注于外在表現,而不是應用程序,同時保持盡量少的開銷。 ** 為什么從模版中分離php很重要?** 兩個主要好處: ◆ **語法:**模版由像html一樣的語義標記構成。php語法在應用程序中運行得很好,但一旦與html結合則迅速惡化。Smarty簡單的{tag}語法專門為外在描述而設計。Smarty專于模版表現而少于“代碼”,這可以加快模版開發同時易于維護。Smarty語法無須懂得php知識,它對程序員與非程序員都是直觀的。 ◆ **隔離:**當php與模版混合,就沒有了何種邏輯類型可以注入到模版的限制。Smarty從php中獨立出了模版,創建了一種從業務邏輯中分離外在表現的控制。Smarty同樣具有安全特性,能夠進一步加強模版的約束。 ** 網頁設計師與php** 一個常見的問題:“網頁美工必須學語法,為什么php不用?!”。當然,網頁設計師可以學php,但這不意味著他們有這個精力去學。他們學習php,然后往模版中添些不屬于他們的東西(如果他們需要的話,你也可以教他們瑞士軍刀),你可以教他們開發應用程序的規則,另一層意思說你也可以叫他們開發者。Smarty為網頁設計師提供所需的恰當工具,為開發人員提供了這些工具的良好控制。 ** 重在實施** 一個在Smarty開發中存在的常見問題是實踐不佳。如果你濫用Smarty的基本面或遇到過這樣的應用程序(比如在模版中嵌入php),為了不使問題變得更糟糕,你可能會對Smarty敬而遠之。在Smarty網站上找到最佳實踐例子參考學習下吧。 ** Smarty是怎么工作的?** 在引擎中,Smarty將模版“編譯”(基于復制和轉換)成php腳本。它只發生一次---當第一次讀取模版的時候,指針前進時調取編譯版本,Smarty幫你保管它,因此,模版設計者只須編輯Smarty模版,而不必管理編譯版本。這也使得模版很容易維護,而執行速度非常快,因為它只是php。當然,php腳本也利用了諸如APC的緩存。 ** 模版繼承** 模版的繼承是Smarty3的新事物,它也是諸多偉大新特性之一。在還未實現模版繼承之前,我們管理著諸如header、footer這樣的模版碎片。這種組織模式適合自身請求一些箍跳(?)的問題,如每個頁面頁眉/頁腳的內容管理。在模版繼承里,我們將保持模版作為獨立頁而不用加載其它頁面。我們可以操縱內容塊繼承它們。這使得模版更直觀、更有效和易管理。可以在Smarty網站瀏覽更多關于模版繼承的內容介紹。 ** 為什么不用xml/xslt語法?** 這里有一堆理由。第一,Smarty應用范圍廣范,除了xml/html基礎模版,還可運用于email、javascript、csv和pdf文檔;第二,xml/xslt語法比php代碼冗長和脆弱,它們對于計算機來說是完美的,但對于人類來說又是極其討厭的。Smarty易于閱讀、理解和維護。 ** 模版安全** 雖然Smarty把你從php中解脫出來,但如果你愿意,仍然可以選擇使用它(php)。模版安全強制約束php(須選擇Smarty相應函數)在使用第三方庫編輯模版時很有用,同時你也不必發動php或Smarty的全部威力解決它們。 ** 整合** 有時,Smarty有點類似MVC模式,但Smarty不是MVC框架,它只是一種描述層,更多地類似如MVC的V部份。事實上,Smarty能夠容易地整合到MVC中的視圖層(V),很多流行的MVC框架指明整合Smarty,或者你也可以在Smarty論壇中找到一些(此類的)幫助文檔。 ** 其它模版引擎** Smarty并不是唯一的遵循“表現與程序代碼分離”理念的引擎。舉例說,一些Python開發商表示將Python代碼與html/css混排不是個好的主意,他們也建立了一些類似的規則,比如Django模板和Cheetah模版。 ** Smarty不是什么** Smarty并不是一個在網站開發中一切從零做起的獨立工具。Smarty只是個從應用程序中剝離表現層的工具。你可以使用攜帶Smarty的已有框架,也可以自己建立代碼庫,使用Smarty作為前端。不管怎樣,Smarty是個從應用程序中抽離出表現層的一個偉大方式。 ** 概述** 不管你用Smarty做個小網站還是建立一個大型企業的解決方案,它都能滿足你的要求。Smarty的許多特性決定它是個偉大的選擇: ◆ 分離php與html/css代碼入人心 ◆ 組織、管理模式清晰 ◆ 為第三方模版實行安全檢查 ◆ 功能完整,按需擴展 ◆ 巨量用戶基礎,非常通用 ◆ 通過LGPL商用許可 ◆ 100%安全,開源工程 ** 我該用Smarty嗎?** Smarty的歷史紀錄表明它能顯著地提高了模版的部署和維護速度。如果你看重應用的可維護性,Smarty是個正確的選擇。然而,Smarty也不是個魔術彈,它只負責管理剝離的表現層。使用Smarty、另一種模版引擎還是單純的php主要取決于你的需要和體驗。如果你喜歡,也可以維護混合php(html/css)的視圖。如果你不需要“干凈”的模版語法、模版繼承、緩存、插件、安全(也就是從php中獨立出來)、快速部署、易于管理,你也可以不用Smarty。最好(決定選擇)的方法是大量詢問別人或親自安裝、測試Smarty,再為你的項目作出一個明智決定。 <table cellspacing="0" cellpadding="0" width="100%" summary="Footer navigation table" border="0"><tbody><tr><td valign="top" align="left" width="33%"><a accesskey="P" href="index.html">Prev</a></td> <td valign="top" align="center" width="34%"><a accesskey="H" href="index.html">Home</a></td> <td valign="top" align="right" width="33%"><a accesskey="N" href="opinion.html">Next</a></td></tr><tr><td valign="top" align="left" width="33%">Smarty - the compiling PHP template engine<br/> Smarty - PHP 模板編譯引擎</td> <td valign="top" align="middle" width="34%">?</td> <td valign="top" align="right" width="33%">Preface to Translation<br/> 譯序</td></tr></tbody></table>
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看