您好,我在 .php 文件中编写了一个函数。即
public static function getCategories($id_lang = false, $active = true, $order = true, $sql_filter = '', $sql_sort = '',$sql_limit = '')
{
if (!Validate::isBool($active))
die(Tools::displayError());
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
SELECT *
FROM `'._DB_PREFIX_.'category` c
LEFT JOIN `'._DB_PREFIX_.'category_lang` cl
ON c.`id_category` = cl.`id_category`
WHERE 1 '.$sql_filter.' '.($id_lang ? 'AND `id_lang` = '.(int)($id_lang) : '').'
'.($active ? 'AND `active` = 1' : '').'
'.(!$id_lang ? 'GROUP BY c.id_category' : '').'
'.($sql_sort != '' ? $sql_sort : 'ORDER BY c.`level_depth` ASC, c.`position` ASC').'
'.($sql_limit != '' ? $sql_limit : '')
);
if (!$order)
return $result;
$categories = array();
foreach ($result AS $row)
{
$categories[$row['id_parent']][$row['id_category']]['infos'] = $row;
}
return $categories;
}
我想在 .tpl 文件中调用此函数。我使用了 {php} {/php}
方式,但这行不通。
这个怎么称呼?
谢谢
最佳答案
Smarty 是一种模板语言 - 如果您想输出函数的结果,请将输出分配给 smarty 变量
$smarty->assign('categories', getCategories($args));
然后在你的模板中使用它
{$categories}
在极少数情况下,这不是正确的模式。
关于php - 如何在 smarty .tpl 文件中调用 php 函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8657551/