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,
site_url() : Returns your site URL, as specified in your config file. The index. php file (or whatever you have set as your site index_page in your config file) will be added to the URL, as will any URI segments you pass to the function, and the url_suffix as set in your config file.
The CodeIgniter 4 anchor() URL helper function accepts an optional 3rd parameter of attributes — as an associative array or a string — according to what your needs are. The following examples cover both variations with the PHP code and resulting raw HTML as viewed in the Chrome Developer console.
Base URL should be absolute, including the protocol: $config['base_url'] = "http://somesite.com/somedir/"; If using the URL helper, then base_url() will output the above string.
By default, URLs in CodeIgniter are designed to be search-engine and human friendly. Rather than using the standard “query string” approach to URLs that is synonymous with dynamic systems, CodeIgniter uses a segment-based approach: example. com/news/article/my_article.
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>
tag
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With