Thinkphp模板中使用自訂函數的方法

來源:互聯網
上載者:User

標籤:http   io   ar   使用   sp   for   檔案   div   on   

注意:自訂函數要放在項目應用目錄/common/common.php中。 這裡是關鍵。 

模板變數的函數調用格式:{$varname|function1|function2=arg1,arg2,### } 

說明: 
{ 和 $ 符號之間不能有空格,後面參數的空格就沒有問題; 

###表示模板變數本身的參數位置 ; 

支援多個函數,函數之間支援空格 ; 

支援函數屏蔽功能,在設定檔中可以配置禁止使用的函數列表 ; 

支援變數緩衝功能,重複變數字串不多次解析。 

使用例子:

  1. {$webTitle|md5|strtoupper|substr=03} 
  2.  {$number|number_format=2} 
  3.  {$varname|function1|function2=arg1arg2### } 
複製代碼

執行個體: 
複製代碼 代碼如下:

  1. function Cate($cid){ 
  2. $Cate=D(‘Cate‘); 
  3. $Cate=$Cate->where(‘id=‘.$cid)->find(); 
  4.  return $Cate[‘title‘]; 
  5.  } 
複製代碼

我想在模板中調用這個函數則在模板中可以這樣寫

    1. {$vo.cid|cate=###} 

 

http://www.thinkphp.cn/topic/1553.html

Thinkphp模板中使用自訂函數的方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.