Smarty中include_php的使用???

jxyuhua jxyuhua 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
以下是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的例子,让我明白它的好处是什么,多谢。
...全文
评论 14
收藏 已收藏
分享
返回顶部
jxyuhua
基础编程 21,889 成员 140,329 内容