CodeIgniter - 正确的方式链接到视图中的另一个页面 [英] CodeIgniter - Correct way to link to another page in a view
问题描述
我想知道是否有人可以告诉我从视图内链接到另一个页面的正确方法。
这是有一个函数,还是只是通常关于
干杯,
您可以创建自己的< a>
标记并在href中插入一个url,像这样
< a href =<?php echo site_url function / uri')?>> Link< / a>
或者您可以使用URL帮助程序生成< a> ;
标签
anchor(uri segments,text,attributes)
所以...使用它...
<?php echo anchor('controller / function / uri','Link','class =link-class')?>
并会生成
< a href =http://domain.com/index.php/controller/function/uriclass =link-class> Link< / a>
对于其他已评论的问题
我会使用我的第一个例子
因此...
code>< a href =<?php echo site_url('controller / function')?>>< img src =<?php echo base_url()?> img / path /file.jpg/>< / a>
图像(和其他资产)我不会把文件路径放在php,只需回显base_url(),然后正常添加路径。
I was wondering if someone could tell me the correct way to link to another page from within a view.
Is there a function for this or is it just the usual about
Cheers,
解决方案I assume you are meaning "internally" within your application.
you can create your own
<a>
tag and insert a url in the href like this<a href="<?php echo site_url('controller/function/uri') ?>">Link</a>
OR you can use the URL helper this way to generate an
<a>
taganchor(uri segments, text, attributes)
So... to use it...
<?php echo anchor('controller/function/uri', 'Link', 'class="link-class"') ?>
and that will generate
<a href="http://domain.com/index.php/controller/function/uri" class="link-class">Link</a>
For the additional commented question
I would use my first example
so...
<a href="<?php echo site_url('controller/function') ?>"><img src="<?php echo base_url() ?>img/path/file.jpg" /></a>
for images (and other assets) I wouldn't put the file path within the php, I would just echo the base_url() and then add the path normally.
这篇关于CodeIgniter - 正确的方式链接到视图中的另一个页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!