PegLeg
(Vemundg)
1
Hi
How can I make a portlet display a text/link only if I’m on a given page or is it possible to make a portlet only to be visible if I’m on a given url.
Is there a function that I can use like this user access thingy:
if(Yii::app()->user->checkAccess('authName')) {
//some code
}
I guess I’m loooking for a way to get the current url.
–
PegLeg
Y11
(Y!!)
2
If you want to display the portlet only for SiteController with actionIndex (route: site/index), you may try something like this:
if (Yii::app()->controller->id === 'site' && Yii::app()->controller->action->id === 'index')
{
// ...
}
// What you also can do is to create a parent controller for all your other controllers like:
class ParentController extends CController
{
public $showMyPortlet;
}
When you want to display the portlet for a specific action you do:
class SiteController extends ParentController
{
public function actionIndex()
{
// enable portlet
$this->showMyPortlet = true;
// other code
}
}
In your layout/widget you then do:
if (Yii::app()->controller->showMyPortlet)
{
// ...
}
PegLeg
(Vemundg)
3
Thanks you just saved me ha whole lot of googling;)