亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

include_php函數(shù)

include_php函數(shù):

include_php 是解決模板元件化的好方法,它使得php 程式碼從模板檔案中被分離出來.?

?舉個例子:假設(shè)有一個從資料庫動態(tài)取出資料用來顯示網(wǎng)站導(dǎo)覽的模板,你可以將得資料內(nèi)容的php 邏輯部分分離出來保存在一個單獨的資料夾下,

並在模板開始的位置包含該php 腳本. 那麼就可以在任何地方包含此模板而不用擔(dān)心之前資料庫訊息是否已被程式取出.

即使是在模板中多次地調(diào)用php 文件,預(yù)設(shè)情況下它們只被包含一次. 你可以設(shè)定once 屬性從而指明每次調(diào)用都重新包含該檔案.?

如果將once 屬性設(shè)為false,每次呼叫該檔案都會被重新包含.

如果設(shè)定了assign 屬性,該屬性對應(yīng)的變數(shù)名稱用於保存待包含php 的輸出,這樣待包含php 檔案的輸出就不會直接顯示了。

在待包含php 檔案中可以透過$this 存取smarty 物件.

##load_nav.php:

<?php
// load in variables from a mysql db and assign them to the template
// 從mysql數(shù)據(jù)庫中取得數(shù)據(jù),將數(shù)據(jù)賦給模板變量require_once("MySQL.class.php"); 
 $sql = new MySQL; 
 $sql->query("select * from site_nav_sections order by name",SQL_ALL); 
 $this->assign('sections',$sql->record);

index.tpl:

{* absolute path, or relative to $trusted_dir *}
{* 絕對路徑或 $trusted_dir 的相對路徑 *}
{include_php file="/path/to/load_nav.php"}
{foreach item="curr_section" from=$sections}
<a href="{$curr_section.url}">{$curr_section.name}</a><br>
{/foreach}


#

繼續(xù)學(xué)習(xí)
||
<?php echo "include_php函數(shù)";