我想知道是否有人可以告诉我从视图中链接到另一个页面的正确方法。
是否有这样的功能,或者只是通常的
干杯,
答案 0 :(得分:65)
我认为您的意思是“内部”在您的应用程序中。
您可以创建自己的<a>
标记,并在href中插入一个网址,如下所示
<a href="<?php echo site_url('controller/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/uri" class="link-class">Link</a>
对于其他评论问题
我会用我的第一个例子
所以...
<a href="<?php echo site_url('controller/function') ?>"><img src="<?php echo base_url() ?>img/path/file.jpg" /></a>
对于图像(和其他资源)我不会把文件路径放在php中,我只是回显base_url()然后正常添加路径。
答案 1 :(得分:1)
最好的方法是使用以下代码:
<a href="<?php echo base_url() ?>directory_name/filename.php">Link</a>
答案 2 :(得分:1)
你也可以使用PHP短标签来缩短它。这是一个例子
<a href="<?= site_url('controller/function'); ?>Contacts</a>
或使用CI的内置锚功能。
答案 3 :(得分:0)
<a href="<?php echo site_url('controller/function'); ?>Compose</a>
<a href="<?php echo site_url('controller/function'); ?>Inbox</a>
<a href="<?php echo site_url('controller/function'); ?>Outbox</a>
<a href="<?php echo site_url('controller/function'); ?>logout</a>
<a href="<?php echo site_url('controller/function'); ?>logout</a>
答案 4 :(得分:0)
最好和最简单的方法是在CodeIgniter中使用锚标记,例如
<?php
$this->load->helper('url');
echo anchor('name_of_controller_file/function_name_if_any', 'Sign Out', array('class' => '', 'id' => ''));
?>
有关详细信息,请参阅https://www.codeigniter.com/user_guide/helpers/url_helper.html
这肯定有用。
答案 5 :(得分:0)
您也可以使用此代码
// test“ class =” btn btn-primary pull-right“>