Smarty中include_php的使用???
以下是Smarty中include_php的源代码:
load_nav.php
<?php
// load in variables from a mysql db and assign them to the template
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 *}
{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}
我不太清楚,这样做的好处是什么?
既然变量$sections已经传给Smarty模板文件了,那再在模板文件里包含PHP文件有什么作用呢?直接使用那个变量不就可以了吗?
能不能给几个include_php的例子,让我明白它的好处是什么,多谢。