[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">
<?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>";
}
?>
</ul>
</div>