CodeIgniter Forums
URL segment depth problems - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: URL segment depth problems (/showthread.php?tid=8686)

Pages: 1 2


URL segment depth problems - El Forum - 05-27-2008

[eluser]floweringmind88[/eluser]
I have links:

<a href="index/variable">A</a> <a href="index/variable">B</a>

The first url works great:
http://www.domain.com/page/index/variable

but then the next link I click on is like:

http://www.domain.com/page/index/index/variable

I was wondering what other people do to keep the URL from going deeper.

Thanks


URL segment depth problems - El Forum - 05-27-2008

[eluser]gtech[/eluser]
use site_url() to include the full path.. you were using a relative path.

<a href="&lt;?=site_url()?&gt;/page/function/variable">A</a>


you have to ensure the base_url and index_page are defined in the config/config.php file.


URL segment depth problems - El Forum - 05-27-2008

[eluser]Michael Wales[/eluser]
Use the anchor() function within the URL class. It will automatically generate your links for you based on the settings found within config.php.

If you don't like that option, and want to do it manually, the site_url() function works great.


URL segment depth problems - El Forum - 05-27-2008

[eluser]GSV Sleeper Service[/eluser]
use the url helper - http://ellislab.com/codeigniter/user-guide/helpers/url_helper.html
site_url() and base_url() are your friends.


URL segment depth problems - El Forum - 05-27-2008

[eluser]Tom Glover[/eluser]
Relative paths do not work in CI.


URL segment depth problems - El Forum - 05-27-2008

[eluser]Michael Wales[/eluser]
Quote:use site_url() to include the full path.. you were using a relative path.

<a href="&lt;?=site_url()?&gt;/page/function/variable">A</a>

Rather:
Code:
&lt;?= site_url('class/function/variable'); ?&gt;



URL segment depth problems - El Forum - 05-27-2008

[eluser]Tom Glover[/eluser]
[quote author="Michael Wales" date="1211920686"]
Quote:use site_url() to include the full path.. you were using a relative path.

<a href="&lt;?=site_url()?&gt;/page/function/variable">A</a>

Rather:
Code:
&lt;?= site_url('class/function/variable'); ?&gt;
[/quote]

You still need the <a> tags around it
Code:
<a href="&lt;?= site_url('class/function/variable'); ?&gt;">A</a>



URL segment depth problems - El Forum - 05-27-2008

[eluser]gtech[/eluser]
Quote:Rather:
Code:
&lt;?= site_url('class/function/variable'); ?&gt;
[/quote]

yep that works to, and probably neater.


URL segment depth problems - El Forum - 05-27-2008

[eluser]floweringmind88[/eluser]
Thanks again!

One last question when I send a variable to my function via the URL how do I access that variable in the HTML.

I tried $variable and $this->variable and neither seems to work.

Chris


URL segment depth problems - El Forum - 05-27-2008

[eluser]Tom Glover[/eluser]
To get a set segment of the url use these functions: http://ellislab.com/codeigniter/user-guide/libraries/uri.html