Welcome Guest, Not a member yet? Register   Sign In
starting CI3
#1

Hello,
I am new with CodeIgniter and now trying to learn using it.
So I started to download and install version 3.0.3 and made the tutorial 'News' as described. All works fine and it gave me a good idea of the basic principals. So with this basic I have I am now playing and adding stuff.
I added the .htaccess file to get rid of the index.php in the url, and that also works fine.
Now I added a menu with the main items of a site. In case of the tutorial news, it has a link to 'home', 'about', and 'news'. And now I am getting problems. When I am on one of the main pages, thereĀ“s no problem, the links are working. e.g.-> http://..codeIgniter-3.0.3/about
But when I have navigated to a newsarticle, e.g. -> http://..codeIgniter-3.0.3/news/weird_1, and i click then on a main menuitem, it cannot find the page, because it keeps the url in the /news/ and the url becomes like this: http://..codeIgniter-3.0.3/news/about, in stead of http://..codeIgniter-3.0.3/about.
How does this work?
Reply
#2

(This post was last modified: 01-09-2016, 02:19 PM by PaulD. Edit Reason: Clarification )

Try defining your urls like this:

PHP Code:
<a href="<?php echo site_url('controller/method/whatever_else'); ?>">My LInk</a

A link like this
Code:
<a href="mylink.html">My link</a>

is relative to the root of the page it is on, and you can use things like ../ to move around.

A link like this
Code:
<a href="/mylink.html">My link</a>
is relative to the site root.

Documentation
http://www.codeigniter.com/userguide3/he...l#site_url

I hope that helps,

Best wishes,

Paul.

PS One of the massive benefits is that when you move your site from production to live, or from one domain to another, or from a root to a sub folder etc. all you have to do is edit one entry in the config file.
Reply
#3

(01-09-2016, 02:18 PM)PaulD Wrote: Try defining your urls like this:

PHP Code:
<a href="<?php echo site_url('controller/method/whatever_else'); ?>">My LInk</a

A link like this
Code:
<a href="mylink.html">My link</a>

is relative to the root of the page it is on, and you can use things like ../ to move around.

A link like this
Code:
<a href="/mylink.html">My link</a>
is relative to the site root.

Documentation
http://www.codeigniter.com/userguide3/he...l#site_url

I hope that helps,

Best wishes,

Paul.

PS One of the massive benefits is that when you move your site from production to live, or from one domain to another, or from a root to a sub folder etc. all you have to do is edit one entry in the config file.

Thanks, it sure helps and works fine.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB