THINKPHP 架構的模板技術

來源:互聯網
上載者:User

標籤:default   檔案   .class   字串   定義函數   efault   ons   ssi   each   

//echo C(‘name‘);

App/Action/IndexAction.class.php檔案夾下的

URL模式

//輸出URL模式
//echo C(‘URL_MODEL‘),‘<br/>‘;
//U(‘Index模組名/方法‘,array(‘id‘=1),‘xxxx html‘,true/false,‘localhost‘),true可直接跳轉
/* 
* 1是預設的url模式
* http://localhost/muke/index.php/Index/user/id/1.html
* 0預設的普通模式
* http://localhost/muke/index.php?m=Index&a=user&id=1
* 2重寫入模式 
* http://localhost/muke/Index/user/id/1.html
* 3相容模式
* http://localhost/muke/index.php?s=/Index/user/id/1.html
*/

自訂函數

//echo U(‘Index/user‘,array(‘id‘=>1),‘html‘,false,‘localhost‘);
//show();
//$arr=array(1,2,3,4,5);
//dump($arr);
//this->display();

模板的賦值和輸出

$name=‘Donsen‘;
//輸出的第一種方法,只能賦值一種變數
$this->name=$name;
//輸出的第二種方法,可以連續賦值
$this->assign(‘name‘,$name);
//$this->assign(‘name‘,$name)->assign(‘sex‘,‘gril‘);

ThinkPHP模板引擎變數輸出和運算

$me[‘name‘]=‘Donsen‘;
$me[‘age‘]=‘22‘;
$this->assign(‘me‘,$me);

index.php模板中輸出
輸出的第一種方法
{$me[‘name‘]}
輸出的第二種方法
{$me.name}
無定義的情況,可以賦值
{$me.sex|default=‘man‘}
運算
{$me[‘age‘]-1}

ThinkPHP模板引擎函數和系統參數

名字加密
{$me[‘name‘]|md5}
字串截取
{$me[‘name‘]|md5|substr=0,5}

volist和foreach
$person=array(
1=>array(‘name‘=>‘Jack‘,‘age‘=>‘18‘),
2=>array(‘name‘=>‘Tom‘,‘age‘=>‘19‘),
3=>array(‘name‘=>‘Peter‘,‘age‘=>‘20‘),
4=>array(‘name‘=>‘Mary‘,‘age‘=>‘21‘),
);
$this->assign(‘person‘,$person);
index.php中迴圈輸出
<volist name=‘person‘ id=‘data‘ offset=‘1‘ length=‘2‘>
{$data[‘name‘]}------{$data[‘age‘]}<br/>
</volist>
volist可利用offset=‘1‘ length=‘2‘截取,但是foreach不能截取
<foreach name=‘person‘ item=‘data‘ >
{$data[‘name‘]}------{$data[‘age‘]}<br/>
</foreach>

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.