Dynamic id for <body> tag in main.php

I have been trying to figure out the best way to add a dynamic id to the <body id="$var"> tag.

Does anyone know if there’s a way to pass variables from the controller action to main.php?


define a property in the controller, $id

call the property in the view via $this->id

a widget also has access to the current controller, see API

calling $this->id from the view currently resulting in ‘user’ for UserController

$this->action->id resulting in ‘update’ for actionUpdate()

I think mbi meant something like this:

class SomeController extends CController {

   public $bodyId='';

   public function actionDemo()




<body id="<?php echo $this->bodyId ?>">


Or you could even add the public var to a base controller (that all your controllers extend from) and set it from a view file.