天天看點

Smarty的知識點總結

smarty的認識和知識點總結:      
smarty什麼樣資料可以正确顯示
  1:字元串
  2:整型
  3:小數
  4:boolean true 顯示1 false  顯示空
  5:array
  6:object 對象

smarty 的if ,foreach
       
{if $name == ''}
    使用者名不能為空
  {/if}
 
  {if $name == ''}
    使用者名不能為空
  {else}
    正确
  {/if}

  $ar = array(1,2,4,22,4);
  foreach($ar as $vo){
    echo $vo;
  }
  {foreach from=$ar item=vo}
     {$vo}
  {/foreach}
           
smarty建立項目:      
0:需求分析 {項目經理->需求分析文檔} 1:靜态頁面html分析 2:建立表
create table t_category(
     id int primary key auto_increment,
     title varchar(20) not null default ''
    );
    
    create table t_new(
     id int primary key auto_increment,
     title varchar(20) not null default '',
     cont varchar(4000) not null default ''
    );
           
3:建立公共程式 news 0:建立檔案夾 db/news.sql common.inc.php 1:設定輸入編碼 2:基準目錄 3:是否顯示錯誤 4:控制顯示錯誤級别 5:時區 6:過濾所有$_POST $_GET資料 sql 注入 4:建立公共類 4.1 資料庫封裝類 pdo 5:分析寫程式 insert into t_user1 values(1,'tom','tom'); select count(id) from t_user where name = '$_POST['name']' and pwd = '$pwd'; 6:引入smarty 7:公共資料類 DbTemplate 模闆 pdo [明天上午]
smarty知識點總結
  重點内容
  smarty:php模闆引擎
  smarty特點:編譯速度快,使用範圍廣!
  1:自定義函數
  1.php
  function test3($args){
   return "";
  }
  $smarty->register_function("test3","test3");
  2.tpl
  {test3}
 
  2:自定義塊
  function test4($args,$con){
   return "";
  }                      //調用test4  原函數
  $smarty->register_block("test4","test4");

  3:自定義變量調節器 插件
    smarty/libs/plugins
    modifiter.test9.php
    function smarty_modifier_test9($str){
     return "";
    }
  4:smarty/libs/plugins 插件
   function.test6.php
   function smarty_function_test6($args,&$smarty){
     return "";
   }

 5:插件方式
   smarty/libs/plugins
   block.test7.php
   function smarty_block_test7($args,$con,&$smarty){
    return "";
    }

 6:加載模闆
   {include file="1.tpl"}
 7:smarty表簽原樣輸出
   {literal}
     {$name}
   {/literal} 
 8:foreach
   {foreach from=$rows item=vo}
     {foreachelse}
     
   {/foreach}
 9:模闆頁面使用php指令
   {php}
    echo "oho";
 10:smarty緩存
   10.1:建立緩存檔案夾
   10.2:$smarty->caching= true;
        $smarty->lifetime = 60;      
謝謝關注websites部落格!