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,
欢呼,
5 个解决方案
#1
62
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
您可以创建自己的标记,并在href中插入这样的url
<a href="<?php echo site_url('controller/function/uri') ?>">Link</a>
OR you can use the URL helper this way to generate an <a>
tag
或者您可以使用URL助手来生成一个标记。
anchor(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.
对于图像(和其他资产),我不会将文件路径放在php中,我只会回显base_url(),然后正常地添加路径。
#2
0
The best way is to use the following code:
最好的方法是使用以下代码:
<a href="<?php echo base_url() ?>directory_name/filename.php">Link</a>
#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
Best and easiest way is to use anchor tag in CodeIgniter like eg.
最好、最简单的方法是在CodeIgniter中使用锚标记,如eg。
<?php
$this->load->helper('url');
echo anchor('name_of_controller_file/function_name_if_any', 'Sign Out', array('class' => '', 'id' => ''));
?>
Refer https://www.codeigniter.com/user_guide/helpers/url_helper.html for details
有关详细信息,请参阅https://www.codeigniter.com/user_guide/helpers/url_helper.html
This will surely work.
这肯定会工作。
#5
0
you can also use PHP short tag to make it shorter. here's an example
您还可以使用PHP短标记使其更短。这里有一个例子
<a href="<?= site_url('controller/function'); ?>Contacts</a>
or use the built in anchor function of CI.
或者使用CI的内建锚函数。
#1
62
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
您可以创建自己的标记,并在href中插入这样的url
<a href="<?php echo site_url('controller/function/uri') ?>">Link</a>
OR you can use the URL helper this way to generate an <a>
tag
或者您可以使用URL助手来生成一个标记。
anchor(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.
对于图像(和其他资产),我不会将文件路径放在php中,我只会回显base_url(),然后正常地添加路径。
#2
0
The best way is to use the following code:
最好的方法是使用以下代码:
<a href="<?php echo base_url() ?>directory_name/filename.php">Link</a>
#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
Best and easiest way is to use anchor tag in CodeIgniter like eg.
最好、最简单的方法是在CodeIgniter中使用锚标记,如eg。
<?php
$this->load->helper('url');
echo anchor('name_of_controller_file/function_name_if_any', 'Sign Out', array('class' => '', 'id' => ''));
?>
Refer https://www.codeigniter.com/user_guide/helpers/url_helper.html for details
有关详细信息,请参阅https://www.codeigniter.com/user_guide/helpers/url_helper.html
This will surely work.
这肯定会工作。
#5
0
you can also use PHP short tag to make it shorter. here's an example
您还可以使用PHP短标记使其更短。这里有一个例子
<a href="<?= site_url('controller/function'); ?>Contacts</a>
or use the built in anchor function of CI.
或者使用CI的内建锚函数。