In the controller (which is a class called MessageController), there is this code, which renders a “view” file named helloWorld and also sets an array where the variable $theTime is connected to the key ‘time’.
$theTime = date("D M j G:i:s T Y");
$this->render('helloWorld',array('time'=>$theTime));
In the view helloWorld file, the key ‘time’ from the controller is displayed here through the variable $time
<h3><?php echo $time; ?></h3>
this works perfectly. However, the book also suggests trying another way. It says
I haven’t been able to figure out how to do this. Anyone know how
A view is rendered as part of CController, so in your example, any class properties and methods can be accessed inside a view using $this.
class MessageController extends CController
{
protected $time;
public function init()
{
$this->time = date("D M j G:i:s T Y");
}
//.. rest of controller code