Welcome Guest, Not a member yet? Register   Sign In
Variable in header seems to get all urls using uri_string(), instead of the current url
#1

[eluser]Unknown[/eluser]
Hello,

I'm new to CodeIgniter, and I have some experience with php. I have more experience with HTML and CSS.

I'm using CodeIgniter in combination with Bootstrap for design purposes.

In my header I'm trying to create a menu, based on a list. This menu should have one of the <li> elements to have class="active" based on the page the user is currently viewing. I'm using the code below to do that.

However, despite of the code, the home <li> element always has class active. This means the first if statement is executed. It seems that the variable $pagina gets all values (home, wiezijnwij, contact) and therefore the first if statement is also true. However, if I echo $pagina, then is shows the correct page (this is confusion to me).

How can I fix this? I think it is related to developing something that makes sure that the $pagina variable does not get all values (how to do that?).

Code:
<div class="span4 offset4">

<ul class="nav nav-pills">

&lt;?php

$pagina = *uri_string*();

// echo $pagina;

if ($pagina = "home")

{

echo "<li class =\"active\"><a href=" . *base_url*() .
">Home</a></li>";

echo "<li><a href=" . *base_url*() . ">Wie Zijn
Wij</a></li>";

echo "<li><a href=" . *base_url*() . ">Contact</a></li>";

}

elseif ($pagina = "wiezijnwij")

{

echo "<li><a href=" . *base_url*() . ">Home</a></li>";

echo "<li class =\"active\"><a href=" . *base_url*() .
">Wie
zijn wij</a></li>";

echo "<li><a href=" . *base_url*() . ">Contact</a></li>";

echo *current_url*();

}

elseif ($pagina = "contact")

{

echo "<li><a href=" . *base_url*() . ">Home</a></li>";

echo "<li><a href=" . *base_url*() . ">Wie zijn
wij</a></li>";

echo "<li class =\"active\"><a href=" . *base_url*() .
">Contact</a></li>";

echo *current_url*();

}

else

{

echo "<li><a href=" . *base_url*() . ">Home</a></li>";

echo "<li><a href=" . *base_url*() . ">Wie zijn
wij</a></li>";

echo "<li><a href=" . *base_url*() . ">Contact</a></li>";

}

?&gt;

</ul>

</div>
#2

[eluser]CroNiX[/eluser]
Do you really think someone can answer that without actually seeing your code?
#3

[eluser]Unknown[/eluser]
[quote author="CroNiX" date="1377792519"]Do you really think someone can answer that without actually seeing your code?[/quote]

Well hello there, friendly sir.

I'm not allowed to place code (because i'm new??), somebody from EllisLab will post it. Obviously this has not yet been done
#4

[eluser]Dan Decker[/eluser]
@CroNiX - Due to some mechanisms in place, new users require the help of EllisLab staff.

Let's keep it friendly and helpful!




Theme © iAndrew 2016 - Forum software by © MyBB