Passing configuration from PHP to JavaScript
You can store application parameters in your configuration file protected/config/main.php that we can access using Yii::app()->params['paramName']. When your application uses the JavaScript code, it is handy to have these parameters available for it. Let's see how to do it in a simple and effective way.
Getting ready
Set up a fresh application using the
yiic webapptool. It should generate an application parameters array inprotected/config/main.php:'params'=>array( // this is used in contact page 'adminEmail'=>'webmaster@example.com', ),
Add additional parameters as follows:
'params'=>array( // this is used in contact page 'adminEmail'=>'webmaster@example.com', 'alert' => array( 'enabled' => true, 'message' => 'Hello there!', ), ),
How to do it...
Create a controller named
protected/controllers/AlertController.phpas follows:<?php class AlertController extends Controller { function actionIndex...