CodeIgniter Forums
starting CI3 - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: starting CI3 (/showthread.php?tid=64064)



starting CI3 - eli - 01-09-2016

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?


RE: starting CI3 - PaulD - 01-09-2016

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/helpers/url_helper.html#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.


RE: starting CI3 - eli - 01-10-2016

(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/helpers/url_helper.html#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.