CodeIgniter -链接到视图中另一页的正确方式

pbossiut  于 2022-12-07  发布在  其他
关注(0)|答案(6)|浏览(125)

我想知道是否有人可以告诉我从视图中链接到另一个页面的正确方法。
这是有什么功能吗?还是只是普通的

uemypmqf

uemypmqf1#

我认为您是指应用程序中的“内部”。

您可以创建自己的<a>标记并在href中插入URL,如下所示

<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://example.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(),然后正常添加路径。

w41d8nur

w41d8nur2#

最好的方法是使用以下代码:

<a href="<?php echo base_url() ?>directory_name/filename.php">Link</a>
oymdgrw7

oymdgrw73#

您还可以使用PHP short标记使其更短。

<a href="<?= site_url('controller/function'); ?>Contacts</a>

或使用配置项的内置锚功能。

2w2cym1i

2w2cym1i4#

最好和最简单的方法是在CodeIgniter中使用锚标记,如eg。

<?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
这肯定会奏效的。

fhg3lkii

fhg3lkii5#

您还可以使用以下代码
//test”class=“btn btn-主拉-右”〉

wgmfuz8q

wgmfuz8q6#

<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>

相关问题