如何在Smarty CodeIgniter中获取基本URL

3

我想使用Smarty与CodeIgniter一起,问题是我以前使用过CodeIgniter但从未使用过Smarty,但我正在努力学习它.. :)

现在有一个小问题,在CodeIgniter中,当我需要baseurl时,我使用这个

<?php echo base_url('styles/bootstrap/css/bootstrap-theme.min.css'); ?>

but how to use it using smarty templates, i mean in smarty .tpl files instead of

i did it like this but it didnt worked for me..

{base_url('styles/bootstrap/css/bootstrap-theme.min.css');}

but got error. i know its not right way but had to try lol..

any ideas?

3个回答

5

您在分号上打了一个小笔误

{base_url('styles/bootstrap/css/bootstrap-theme.min.css')}

注意 :

在显示模板之前必须加载url_helper


1
您可以像这样使用,我没有测试过。
{'styles/bootstrap/css/bootstrap-theme.min.css'|base_url}

或者你可以在模板中编写PHP代码。
{php}
  $this->assign('my_url',base_url('styles/bootstrap/css/bootstrap-theme.min.css'));
{/php}

{$my_url}

请查看这个链接:http://www.smarty.net/docsv2/zh_cn/language.function.php.tpl


1
我已经在表单操作中使用了这个函数来重定向到我的方法,它起作用了。
{base_url('my_controller/my_method')}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接