pokepsw
(Pokepsw)
1
I’m a Yii newbie but have experience with PHP. I’m working on a site that is running on the Yii Framework.
Yii Framework Version: 1.1.4
Goal: I’m trying to add IDs and/or Classes to links (i.e. Sign In, Sign Out) that are built using an array. Here is the code:
<?php
class WUserMenu extends UMenuWorklet
{
public $show = true;
public function accessRules()
{
return array(array('allow','users'=>array('*')));
}
public function properties()
{
return array(
'items'=>array(
array('label'=>$this->t('Sign In'), 'url'=>array('/user/login'), 'visible' => app()->user->isGuest),
array('label'=>$this->t('Sign Up'), 'url'=>array('/user/login'), 'visible' => app()->user->isGuest), //added this 1-25-12
//array('label'=>$this->t('Sign Out'), 'url'=>array('/user/logout'), 'visible' => !app()->user->isGuest),
array('label'=>$this->t('My Stuff'), 'url'=>array('/deal/coupons'), 'visible' => !app()->user->isGuest)
),
'htmlOptions'=>array(
'class' => 'clearfix'
)
);
}
public function taskRenderOutput()
{
if(!app()->user->isGuest)
{
$model = app()->user->model();
$model->scenario = 'fullName';
$this->render('welcome', array('model'=>$model));
}
parent::taskRenderOutput();
}
}
I tried adding this in the array: ‘active’=>$this->id==‘default’, but it didn’t work.
Any help is GREATLY appreciated!
rookie84
(Lifeline Is)
2
If i got your question, here’s how you can do it:
//For adding a class to a link
‘url’=>array(’/deal/coupons’), ‘linkOptions’ => array(‘class’ => ‘activeLink’)
Thanks.
pokepsw
(Pokepsw)
3
Thanks, but that didn’t work. All it did was add another LI to the UL that contains those links. No class was added.
I just want to add a class to one of the links in this array:
public function properties()
{
return array(
'items'=>array(
array('label'=>$this->t('Sign In'), 'url'=>array('/user/login'), 'visible' => app()->user->isGuest),
array('label'=>$this->t('Sign Up'), 'url'=>array('/user/signup'), 'visible' => app()->user->isGuest), //added this 1-25-12
//array('label'=>$this->t('Sign Out'), 'url'=>array('/user/logout'), 'visible' => !app()->user->isGuest),
array('label'=>$this->t('My Stuff'), 'url'=>array('/deal/coupons'), 'visible' => !app()->user->isGuest)
),
'htmlOptions'=>array(
'class' => 'clearfix'
)
);
}
rookie84
(Lifeline Is)
4
You didn’t get my answer really, to whatever item you want a class assigned, just add this to the array:
'linkOptions' => array('class' => 'activeLink')
The code i shared earlier was just an example.