简体   繁体   English

在Smarty中创建URL模板变量

[英]Create URL template variable in Smarty

I have the following PHP to create a list of categories in Smarty. 我有以下PHP在Smarty中创建类别列表。

$result_categories = $con->query("SELECT * FROM categories WHERE u_id='$blog_user[id]'");
$list_categories=array();
while ($row_categories = $result_categories->fetch_assoc())
{
$list_categories[]=$row_categories;
}

I want to make a template variable to get the proper link of a category. 我想制作一个模板变量来获取类别的正确链接。 For example http://domain.com/username/category.php?id=*CAT_ID* as {$Variable} or {$row_categories.variable} (after what`s most appropriate) 例如http://domain.com/username/category.php?id=*CAT_ID*作为{$Variable}{$row_categories.variable} (在最合适的位置之后)

How can i manage this? 我该如何处理? Thanks in advance. 提前致谢。

If I understood you correctly, you can try the following: 如果我对您的理解正确,则可以尝试以下操作:

while ($row_categories = $result_categories->fetch_assoc())
{
$list_categories[]=$row_categories;
$info_smarty->assign('variable',$list_categories); //or however you assign your variables
}

And in your smarty template you can call only 1 link: 在您的智能模板中,您只能调用1个链接:

{$variable[0]}

Or every link: 或每个链接:

{foreach item=links from=$variable} 
{$links}
{/foreach}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM