Welcome Guest, Not a member yet? Register   Sign In
[SOLVED]first URI segment doesn't change after link with second URI segment
#1

[eluser]reaper_unique[/eluser]
Searched but didn't find anything related so I made a new thread.
I have a page /forex.
When I visit a subsegment of that page, it goes to that page and everything, /forex/trading, no problems so far.
But when I get back to, say home, the first segment stays forex and the second segment changes to home.
Now, why doesn't the first segment change to home again? Why does the first segment stay forex?

the links in my menu are
Code:
href ="home">Home>/a>
href ="forex">Home>/a>
etc.

anybody know how I can fix this "beginners" problem.

Thx

EditConfusedolved, see last comment.
#2

[eluser]Eric Barnes[/eluser]
Use the site_url or anchor helper. It will automatically sort out paths for you.
#3

[eluser]reaper_unique[/eluser]
But can you tell me why that is happening?
#4

[eluser]InsiteFX[/eluser]
Sure! because href is expecting the full url path...

InsiteFX
#5

[eluser]reaper_unique[/eluser]
but how come I can switch easily between pages that only use one segment like home, forex or contact? But when I go to a page that has an extra segment like forex/trading and then go back it keeps the first segment?

Is it because it will see the last segment of forex/trading as the first segment again?
If this is the case, is adding site_url or using the anchor helper the only way to solve it ?
#6

[eluser]InsiteFX[/eluser]
Because CodIgniter figures the rest of the url out!

Use the site_url or anchor tag, as Eric mentioned above.

InsiteFX
#7

[eluser]William Rufino[/eluser]
If you are in a page like

localhost/forex/trading

and you have a link with href="home", html will recognise the anchor as localhost/forex/trading/home

it just adds the home to the end...
#8

[eluser]Mat-Moo[/eluser]
Just change
Code:
href ="/home">Home>/a>
href ="/forex">Forex>/a>
/ Will tell it to go to the root folder, and not a folder in the current level
#9

[eluser]reaper_unique[/eluser]
Thanks for the replies but just to be clear, "home", "forex", etc. are the segments that refer to the controllers and thus to the index method which loads the "basic" page(/view). "Forex/trading" is referring to the controller "forex" and the method "trading" thus loading the "subpage"(/subview).

I've set a base url but because I'm not allowed to post links I can't give it to you.

The problems lays with the fact that when I visit "base_url/forex/trading", that "forex" stays in the URL when I want to go to, for example, the home page which is linked in the main menu through
Code:
<a href = "home">Home</a>

so instead of going to
Code:
base_url/index.php/home
I go to
Code:
base_url/index.php/forex/home

adding "/" to the links doesn't help, because I don't want to go to the root. That links me to localhost/home instead of base_url/home.

doing:
Code:
a href="&lt;?php echo site_url();?&gt;/home">Home</a>

obviously works, but I want to keep the php in my views as low as possible.

Edit:
Oh stupid me, I just had to add "../" and it works XD
for some reason I did something wrong the first time I tried it.

Thanks for the replies though, really stupid how I wasted my time on this.


Edit 2:
While I'm at it, might as well ask if it's possible to make a newsletter signup function that I can call upon everytime I load a page?
#10

[eluser]William Rufino[/eluser]
the right way:
Code:
a href="&lt;?php echo site_url('home');?&gt;">Home</a>




Theme © iAndrew 2016 - Forum software by © MyBB