Yii-如果当前页面与链接相同,如何创建与类的链接


Yii - How do a make a link with a class if the current page is the same of the link?

例如,我有这样的结构:

<div id="menuPainelSuperior">
 <a href="<?= CController::createUrl('site/seu_cadastro')?>">Cadastro</a>
 <a href="<?= CController::createUrl('site/lista_clientes') ?>">Clientes</a>
 <a href="<?= CController::createUrl('site/projetos') ?>">Projetos</a>
 <a href="<?= CController::createUrl('site/orcamentos') ?>">Orçamentos</a>
</div>

如果当前页面是"domain.com/site/sue_cadastro",我希望第一个链接具有以下类:"activePageMenu"

有人知道怎么做吗?

您可以在链接上放置if语句,以查看当前控制器和操作是否与您在链接中放置的控制器和操作相同。你得到的是这样的:

$controller = Yii::app()->controller->id;
$action =  Yii::app()->controller->action->id;
$class = '';
if($controller == 'site' && $action == 'seu_cadastro') $class = 'activePageMenu';
echo CHtml::link('Cadastro',array('site/seu_cadastro'),array('class'=>$class));

您是否考虑过使用内置CMenu来实现这一点??

更新:Pitchinnate的回答也是一种方法。