For example in the menu there are links to navigate through the pages. When clicking on a link, a certain page is loaded, and the link itself receives a class " active " with highlighting, for example. How to implement it? I concluded the links in the array, pkhp displays them in a loop and checks if the href matches the gett request, the link gets the class "active". But this is a jumble of code and presentation. Something tells me that everything is done wrong ... And how?
- it all depends on how everything else is arranged ... - zb '
- @eicto, I think it doesn't matter. In general, it would be. General implementation. I have the Stat.property of Router :: route, which contains href links, for example, "main", "login" and links, respectively, href = "/ main", href = "/ login", loop through the links in a loop, and now - if there is a match - lights. I do not like something this. - Deus
|
1 answer
Crutch # 1:
<style type="text/css"> #<?=$menu_active_item?> { //стиль css для подсвеченного элемента } <style>
Crutch # 2
function a($path,$html=''){ $active=''; if($path==$_GET['controller'].'/'.$_GET['action']){ $active = 'active'; } printf('<a class="menuitem %s" href="/%s">%s<a>',$active,$path,$html); }
Without crutches - create a normal function in view that accepts an array or object. It is even better if this object can draw itself. So yes, you will have a check, but the cycle on the page will be as in the second version:
foreach($menu_items as $item){ draw_menu_item($item['path'],$item['html']); }
With object:
foreach($menu_items as $item){ $item->draw(); }
|