Welcome Guest, Not a member yet? Register   Sign In
Url helper
#1

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
Reply
#2

(This post was last modified: 11-20-2017, 08:22 AM by PaulD.)

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/h...l#site_url
Reply
#3

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
Reply
#4

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




Theme © iAndrew 2016 - Forum software by © MyBB