Właśnie napisałem dla własnych potrzeb od nowa funkcję anchor w helperze url_helper.php.
Co zostało zmienione i dodane?
Funkcja została napisana tak, że gdy jesteśmy na danej stronie to u nas w menu, odnośnik który prowadzi do strony na której właśnie jesteśmy, zostaje wyróżniony.
Wystarczy zamienic stary kod z funkcja anchor, na moj.
<?php // ------------------------------------------------------------------------ /** * Anchor Link * * Creates an anchor based on the local URL. * * @access public * @param string the URL * @param string the link title * @param mixed any link class * @param mixed any link class now * @param mixed url name * @param mixed URL segment * @param mixed AOTT * @param mixed Text style start * @param mixed Text style end * @return string */ function anchor($uri = '', $title = '', $a_class = '', $class_now = '', $url_name = '', $segment = 1, $aott = FALSE , $text_style1 = '', $text_style2 = '') { $CI = get_instance(); $get = $CI->uri->segment($segment); $title = (string) $title; // Generowanie adresu strony { } else { $site_url = site_url($uri); } // Nazwa odnośnika if ($title == '') { $title = $site_url; } // Ustalanie klasy if ($a_class != '') { $attributes = 'class=\"'.$a_class.'\"'; } // Ustalanie kiedy ma byc zaznaczone if($aott == FALSE && $get == $CI->uri->segment(1) && $CI->uri->segment(2) != NULL) { $class = ''; } else { if($get == $url_name) { $class = 'class=\"'.$class_now.'\"'; } else { $class = $a_class; } } return '<a href=\"'.$site_url.'\" title=\"'.$title.'\" '.$class.'>'.$text_style1.''.$title.''.$text_style2.''; } ?>
Krótkie wyjaśnienie
<?php anchor('nazwapliku','wyswietlana nazwa', 'nazwa klasy linku', 'nazwa klasy jezeli ta strone aktualnie ogladamy', 'fragment adresu ktory ma sprawdzic', ktory segment linku ma sprawdzac, [b]FALSE[/b], 'costam linku, np. ', 'zakonczenie '); ?>
Przepraszam, ale ja kompletnie nie potrafię tłumaczyć :/. To False gdzie pogrubiłem, już w ogóle nie mam pojęcia jak wam wytlumaczyc. Uważam, że ktoś znający się na programowaniu choć troszeczkę, powinien patrząc na kod zrozumieć co jest od czego. Co do phpdocumentator - dopiero się uczę

Mam nadzieję, że komuś się przyda.
Jeszcze takie porównanko tego z html'em:
<?php anchor('site/portfolio','Moje Portfolio', 'klaskac', 'now', 'portfolio', 2, FALSE, '', ''); ?>
odpowiada
<a href=\"'.$site_url.'\" title=\"'.$title.'\" '.$class.'>
^ Cos sie jebie, nie moge tego poprawic -.-
</a href=\"'.$site_url.'\" title=\"'.$title.'\" '.$class.'>