include_php

PHP Smarty

Smarty - the compiling PHP template engine
Prev 来源:PHP中文社区 Chapter 7. Built-in Functions[第七章.内建函数] Next

include_php

Attribute Name Type Required Default Description
file string Yes n/a The name of the php file to include
once boolean No true whether or not to include the php file more than once if included multiple times
assign string No n/a The name of the variable that the output of include_php will be assigned to
属性 类型 是否必须 缺省值 描述
file string Yes n/a 待包含php文件的名称
once boolean No true 如果待包含php文件已被包含是否仍然包含(类似php中的include_once函数)
assign string No n/a 该属性指定一个变量保存待包含php文件的输出
load_nav.php
-------------

<?php

	// load in variables from a mysql db and assign them to the template
	// 从mysql数据库中取得数据,将数据赋给模板变量
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}
 

Prev 来源:PHP中文社区 Home Next
include Up insert