我怎样才能用更少的代码来简化它?
<?php
$items['link1'] = 'Link 1';
$items['link2'] = 'LInk 2';
$items['link3'] = 'Link 3';
?>
<?php foreach ($items as $url => $text): ?>
<?php $class = false; if (isset($active) and $active == $url) $class = array('class' => 'current'); ?>
<?php echo '<li>' . Html::anchor($url, $text, $class) . '</li>' ?>
<?php endforeach; ?>
而且,由于某种原因,“当前”类在特定 URL 上时未显示。
谢谢