smarty include_php 加载php文件

作者:袖梨 2022-07-02

Example 7-21. function {include_php}

The load_nav.php file:

// load in variables from a mysql db and assign them to the template
require_once('database.class.php');
$db = new Db();
$db->query('select url, name from navigation order by name');
$this->assign('navigation', $db->getRows());

?> 

在模板中我们如下设置

{* absolute path, or relative to $trusted_dir *}
{include_php file='/path/to/load_nav.php'}

{foreach item='nav' from=$navigation}
  {$nav.name}

{/foreach}

 

相关文章

精彩推荐