導航:首頁 > 編程語言 > smartyphp方法

smartyphp方法

發布時間:2022-10-20 07:58:16

㈠ smarty 模板怎樣使用php標簽

smarty本身是不推薦使用php標記的,可以通過編寫插件(block,function,modifier)來代替。
smarty默認不開啟php標記,需要在創建smarty對象後做如下設置:
$smarty->php_handling = SMARTY_PHP_ALLOW ;

㈡ smarty 用php類的靜態方法獲取數據的同時assign了一個數組,模版如何獲取這個數組變數

給你兩個建議:
1.在php頁面獲取數據後,注冊到模板輸出
-------PHP頁面----------
$data=Proct::getdata();
$smarty->assign('data',$data);
------模板頁面--------
{section data=$data name="customer"}
<td>{$data[customer].price}</td>
{/section}

2.使用插件技術(block,function都可以),具體書寫方法參考smarty手冊中插件部分

㈢ Smarty和php

沒看懂樓主的提問,如果是想把php的結果顯示在smarty的頁面上,這樣寫:

<php

require 'smarty.php';

$smarty->assign('key',$value); //給key賦值

$smarty->display('你的頁面.html');

你的模板頁面里用{$key}就可以顯示對應值
或者用
{foreach $key as $itemkey=>$value}
{$itemkey},{$value}
{/foreach}流程式控制制

㈣ smarty模板引擎有什麼用,php中怎麼用

smarty是一個使用PHP寫出來的模板PHP模板引擎.它提供了邏輯與外在html內容的分離.
作用:就是要使用PHP程序員同美工分離,使用的程序員改變程序的邏輯內容不會影響到美工的頁面設計,美工重新修改頁面不會影響到程序的程序邏輯,這在多人合作的項目中顯的尤為重要。
具體使用方法是,先將smarty核心文件引入,然後做配置,然後賦值變數到模板,最後到模板進行解析就可以了。
參考教程:http://leadtodream.blog.163.com/blog/static/18520043920151711534369/

㈤ php中smarty疑問

void display (string template [, string cache_id [, string compile_id]])

該函數原形為display(string varname),作用為顯示一個模板。簡單的講,它將分析處理過的模板顯示出來,這里的模板文件不用加路徑,只要使用一個文件名就可以了,它路徑我們已經在$smarty->templates(string path)中定義過了。

程序執行完後我們可以打開當前目錄下的templates_c與cache目錄,就會發
現在下邊多出一些%%的目錄,這些目錄就是Smarty的編譯與緩存目錄,它由
程序自動生成,不要直接對這些生成的文件進行修改。

第二個可選參數指定一個緩存號,相關的信息可以查看緩存。

通過第三個可選參數,可以指定一個編譯號。這在你想把一個模板編譯成不同版本時使用,比如針對不同的語言編譯模板。編譯號的另外一個作用是,如果你有多個$template_dir模板目錄,但只有一個$compile_dir編譯後存檔目錄,這時可以為每一個$template_dir模板目錄指定一個編譯號,以避免相同的模板文件在編譯後會互相覆蓋。相對於在每一次調用display()的時候都指定編譯號,也可以通過設置$compile_id編譯號屬性來一次性設定。

㈥ smarty怎麼引入php文件

<?php
/**
*
* @version $Id: index.php
* @package
* @author www.php100.com
* @action 顯示實常式序
*/
include_once("./Smarty/Smarty.class.php"); //包含smarty類文件
$smarty = new Smarty(); //建立smarty實例對象$smarty
$smarty->templates("./templates"); //設置模板目錄
$smarty->templates_c("./templates_c"); //設置編譯目錄
$smarty->cache("./cache"); //緩存目錄
$smarty->cache_lifetime = 0; //緩存時間
$smarty->caching = true; //緩存方式
$smarty->left_delimiter = "{#";
$smarty->right_delimiter = "#}";
$smarty->assign("name", "zaocha"); //進行模板變數替換
$smarty->display("index.htm"); //編譯並顯示位於./templates下的index.htm模板
?>

參考:smarty半小時快速上手教程
http://www.chinaz.com/program/2010/0224/107006.shtml

㈦ thinkphp中如何用內置的smarty調用php中自定義的函數

可以自己寫個smarty插件,我以前寫過,你根據smarty手冊上的提示也可以寫出來的。相信自己!

這是我以前寫的,轉換時間的:

<?php
/**
*時間顯示,將Unix時間或普通時間和轉為生活時間用語
*/
functionsmarty_modifier_life_time($string)
{
if(strpos($string,'-')||strpos($string,'.'))
{
$string=strtotime($string);
}
$res=time()-$string;
if($res<=60)
{
return'1分鍾前';
}elseif($res<=3600){
if($res>=1800&&$res<=1800+60) return'半小時前';
returnfloor($res/60).'分鍾前';
}elseif($res<=3600*24){
if($res>=3600*12&&$res<=3600*12+3600) return'半天前';
returnfloor($res/3600).'小時前';
}elseif($res<=3600*24*30){
if($res>=3600*24*15&&$res<=3600*24*15+3600*24) return'半個月前';
returnfloor($res/(3600*24)).'天前';
}elseif($res<=3600*24*30*365){
if($res>=3600*24*30*6&&$res<=3600*24*30*6+3600*24*30) return'半年前';
returnfloor($res/(3600*24*30)).'月前';
}else{
if($res>=3600*24*30*365&&$res<=3600*24*30*365+3600*24*30) return'一年前';
returndate('Y-m-dH:i',$string);
}
}
?>

㈧ php中怎麼使用smarty

首先你需要有smarty的包,然後你導入smarty的文件,那個文件裡面有對應的參數設置,你可以看著那個文件來設置對應的參數

㈨ smarty標簽里的值如何傳到php標簽中

已經assign一個模版變數$assign,由於要做特殊的循環輸出,使用for循環,因此使用到了php標簽,但是php語句和模版語句的變數作用域是不同的,因此不能直接獲取到
{{php}}
for($i=0;$i<count($assign);$i=$i+2){
echo'
<ul>
<li><spanclass="zz_pic"><ahref="'._url('picture',array('col_key'=>'cert','pic_id'=>$assign[$i][pic_id])).'"title=""><imgsrc="uploads/thumb_'.$assign[$i][pic].'"alt=""></a></span><spanclass="zz_title"><ahref="'._url('picture',array('col_key'=>'cert','pic_id'=>$assign[$i][pic_id])).'"title="">'.$assign[$i][title].'</a></span></li>
<li><spanclass="zz_pic"><ahref="'._url('picture',array('col_key'=>'cert','pic_id'=>$assign[$i+1][pic_id])).'"title=""><imgsrc="uploads/thumb_'.$assign[$i+1][pic].'"alt=""></a></span><spanclass="zz_title"><ahref="'._url('picture',array('col_key'=>'cert','pic_id'=>$assign[$i+1][pic_id])).'"title="">'.$assign[$i+1][title].'</a></span></li>i>
</ul>';}
{{/php}}
解決的方法是:模版變數全部存在smarty的一個對象裡面;只要在for之前進行賦值:$assign=$this->_tpl_vars[assign];
{{php}}
$assign=$this->_tpl_vars[assign];
for($i=0;$i<count($assign);$i=$i+2){
echo'
<ul>
<li><spanclass="zz_pic"><ahref="'._url('picture',array('col_key'=>'cert','pic_id'=>$assign[$i][pic_id])).'"title=""><imgsrc="uploads/thumb_'.$assign[$i][pic].'"alt=""></a></span><spanclass="zz_title"><ahref="'._url('picture',array('col_key'=>'cert','pic_id'=>$assign[$i][pic_id])).'"title="">'.$assign[$i][title].'</a></span></li>
<li><spanclass="zz_pic"><ahref="'._url('picture',array('col_key'=>'cert','pic_id'=>$assign[$i+1][pic_id])).'"title=""><imgsrc="uploads/thumb_'.$assign[$i+1][pic].'"alt=""></a></span><spanclass="zz_title"><ahref="'._url('picture',array('col_key'=>'cert','pic_id'=>$assign[$i+1][pic_id])).'"title="">'.$assign[$i+1][title].'</a></span></li>i>
</ul>';}
{{/php}}

㈩ PHP 中 smarty 要怎麼 配置

首先要載入smarty類:Smarty.class.php
然後實例化這類:如$smarty=new Smarty()
主要的幾個基本配置:
$smarty->template_dir //設置模板目錄
$smarty -> compile_dir //設置編譯目錄
$smarty -> config_dir //設置配置文件目錄
$smarty-> caching //設置緩存狀態
$smarty-> cache_dir //設置緩存的路徑
$smarty -> debugging //是否允許調試
$smarty -> left_delimiter //設置左定界符
$smarty-> right_delimiter //設置右定界符
$smarty -> cache_lifetime //設置緩存的時間
使用一般就assign(); display();

閱讀全文

與smartyphp方法相關的資料

熱點內容
rf3148編程器 瀏覽:505
浙江標准網路伺服器機櫃雲主機 瀏覽:587
設置網路的伺服器地址 瀏覽:600
java圖形界面設計 瀏覽:751
純前端項目怎麼部署到伺服器 瀏覽:538
瓜子臉程序員 瀏覽:505
如何保證伺服器優質 瀏覽:94
小微信aPP怎麼一下找不到了 瀏覽:299
演算法纂要學術價值 瀏覽:975
程序員你好是什麼意思 瀏覽:801
倩女幽魂老伺服器如何玩 瀏覽:561
電子鍾單片機課程設計實驗報告 瀏覽:999
看加密頻道 瀏覽:381
程序員算不算流水線工人 瀏覽:632
三星電視我的app怎麼卸載 瀏覽:44
簡述vi編譯器的基本操作 瀏覽:507
讓程序員選小號 瀏覽:91
加強數字貨幣國際信息編譯能力 瀏覽:584
購買的app會員怎麼退安卓手機 瀏覽:891
程序員的種類及名稱 瀏覽:295