Welcome Guest, Not a member yet? Register   Sign In
How to use base_url
#1

[eluser]ronn[/eluser]
In my config file I have the base url set up as
Code:
$config['base_url']="http://localhost/public/";
I'm using it in one of my views for my page navigation like below:

Code:
<ul id="menu1" class="menu">
    <li>
        <a href="&lt;?php base_url()?&gt;/landing">Home</a>
    </li>
    <li>
        <a href="#">Products</a>
        <ul>
            <li><a href="&lt;?php base_url()?&gt;/products/hardware">Hardware Products</a></li>
            <li><a href="products/software">Software Products</a></li>
        </ul>
    </li>
    <li><a href="&lt;?php base_url()?&gt;/services">Services</a></li>
    <li>
        <a href="&lt;?php base_url()?&gt;/contact">Contact Us</a>
    </li>
    <li>
        <a href="&lt;?php base_url()?&gt;/about">About</a>
    </li>
</ul>

When I view the result in the webbrower it is taking out the /public/ from the URL. Why would this be? I would think the URL would look like:
Code:
http://localhost/public/about
instead it looks like:
Code:
http://localhost/about
Am I incorrect in the use of the base_url?
#2

[eluser]ronn[/eluser]
I have found a solution. I simply added echo to the statement. So that way it writes the base_url to the page. Let me know if there is still a better way.
#3

[eluser]JanDoToDo[/eluser]
if u dont want echo: &lt;?=base_url()?&gt;
#4

[eluser]Twisted1919[/eluser]
For what are you doing , go with site_url('landing');
Use site_url('uri/segments') for links and base_url() for images paths,css, things like this .
#5

[eluser]ronn[/eluser]
Great. That worked very well. Thanks
#6

[eluser]gh0st[/eluser]
Also you can use:

Code:
&lt;base href="&lt;?=base_url();?&gt;" /&gt;

In your head, that way you don't need to put it in every time.
#7

[eluser]Twisted1919[/eluser]
[quote author="gh0st" date="1265933558"]Also you can use:

Code:
&lt;base href="&lt;?=base_url();?&gt;" /&gt;

In your head, that way you don't need to put it in every time.[/quote]
site_url() is better because it adds suffix to your urls if it's the case , also true for index.php in front of your controller name .
#8

[eluser]danmontgomery[/eluser]
[quote author="Twisted1919" date="1265943136"][quote author="gh0st" date="1265933558"]Also you can use:

Code:
&lt;base href="&lt;?=base_url();?&gt;" /&gt;

In your head, that way you don't need to put it in every time.[/quote]
site_url() is better because it adds suffix to your urls if it's the case , also true for index.php in front of your controller name .[/quote]

http://w3schools.com/tags/att_base_href.asp




Theme © iAndrew 2016 - Forum software by © MyBB