CodeIgniter Forums
Url helper - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=11)
+--- Thread: Url helper (/showthread.php?tid=69424)



Url helper - blackiven - 11-20-2017

Hi,

I use Codeigniter Version 3.1.6

Here is my bootstrap navbar:


Code:
<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <a class="navbar-brand" href="#">ciBlog</a>
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarColor03" aria-controls="navbarColor03" aria-expanded="false" aria-label="Toggle navigation" style="">
    <span class="navbar-toggler-icon"></span>
  </button>

  <div class="collapse navbar-collapse" id="navbarColor03">
    <ul class="navbar-nav mr-auto">
      <li class="nav-item active">
        <a class="nav-link" href="<?php echo base_url(); ?>">Home <span class="sr-only">(current)</span></a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="<?php echo base_url(); ?>/about">About</a>
      </li>
    </ul>
    
  </div>
</nav>

Don't know but the links under Home and About are not working correctly.
Please help me. Thanks.

Regards


RE: Url helper - PaulD - 11-20-2017

You should use site_url here.

PHP Code:
<a href="<?php echo site_url(); ?>">Home</a>

<
a href="<?php echo site_url('about'); ?>">about</a// calls controller 'about' with method 'index'


<a href="<?php echo site_url('info/about'); ?>">about</a// calls controller 'info' with method 'about' 

https://www.codeigniter.com/user_guide/helpers/url_helper.html#site_url


RE: Url helper - blackiven - 11-20-2017

This is the output with "echo"

http://localhost/blog/localhost/blog

and without "echo"

http://localhost/blog



If I click on About it shows me a wrong URL under Home


RE: Url helper - blackiven - 11-20-2017

It is all ok, I typed the wrong URL in config file.