CodeIgniter Forums

Full Version: how to write corect a href links in ci?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]sorin.ruse[/eluser]
Hi Guys,

I've started to develop an web app using ci and i'm somehow confused on how the urls are working.

Let me explain:
1. I have rewrite engine on;
2. My controler 'main' based on some validation points to the 'site' controler which loads the view 'site_view';
3. After the load of the view my url is: http:/mydomain.com/site;
4. On the site_view page i have an <a> tag pointing to the 'site/myfunction' myfunction beeing another function in the same controler 'site' that loads dinamicaly a certain portion of the 'site_view'.
5. At the first trigger of the <a> link everything is loading ok and now my new url is : http://mydomain.com/site/myfunction
PROBLEM:
If I trigger again the same <a> link my url will become: http://mydomain.com/site/site/myfunction and its quite clear that inside my 'site' controler there is no 'site/myfunction' but only 'myfunction'.

Question: Is the base_url().'site/myfunction' the only solution?

Thanks all in advance

El Forum

[eluser]CroNiX[/eluser]
You didn't show how you are writing the links that don't work.

Yes, base_url('controller/method') is one way.
Another is to use the anchor() function which is part of the url helper
Another is to NOT use relative paths in your links and start them with a /...like
Code:
<a href="/controller/method">The Link</a>

El Forum

[eluser]sorin.ruse[/eluser]
Hi CroNIX,

Thanks for your reply.

Using anchor() is definitly my option. Its much simplier to write instead of
using every time the base_url() function.

Thanks again.