#The easiest way to add dynamic content is to embed PHP statements in the view template file. Any code between the tags will be executed.
<h3><?php echo date("D M j G:i:s T Y"); ?></h3>
In the view file: $theTime=date("D M j G:is T Y");
$this->render('helloWorld',array('time'=>$theTime));
Define public properties of a class in the controller instead of local variables. Then access the properties of this class through $this in the view. <h3><?php echo $time; ?></h3>
class MessageController extends Controller { public $time; public function actionHelloworld() { $this->time = date("D M j G:is T Y"); $this->render('helloworld', array('time' => $theTime)); }
The above is the detailed content of How to pass variables to template in Yii. For more information, please follow other related articles on the PHP Chinese website!