CodeIgniter Forums
anchor problem - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: anchor problem (/thread-13659.html)



anchor problem - El Forum - 12-01-2008

[eluser]sojic[/eluser]
Code:
($row->link==$this->uri->segment(2)) ? $attr = array('class' => 'active') : $attr = array();
    $link = array($parent, $row->link);
    $out.='<li>' .anchor($link, $row->text, $attr) . '</li>';

The idea is to detect active page and to add class="active".

The result is <a href="link">


anchor problem - El Forum - 12-01-2008

[eluser]Michael Wales[/eluser]
You are passing an array to the first parameter of anchor(), it should be a string.

I assume this is within some sort of loop that is building out a menu and $parent has been defined elsewhere in the loop (as the first segment of the URL to link to). Maybe something like this:

Code:
if ($row->link === $this->uri->segment(2)) ? $attr = array('class' => $active) : $attr = array();
  $link = $parent . $row->link;
  $out .= '<li>' . anchor($link, $row->text, $attr) . '</li>';
}



anchor problem - El Forum - 12-02-2008

[eluser]sojic[/eluser]
Thanks, I think that it solve the problem. I will try it later