Welcome Guest, Not a member yet? Register   Sign In
URL segment depth problems
#1

[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
#2

[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.
#3

[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.
#4

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

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

[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;
#7

[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>
#8

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

yep that works to, and probably neater.
#9

[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
#10

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




Theme © iAndrew 2016 - Forum software by © MyBB