Including resources in the page
Yii has a special class named CClientScript that can help include scripts, CSS, and other resources in the page.
How to do it...
We will start with including a script. There are three types of scripts: external scripts, core scripts, and inline scripts.
External script is a script located in a file and accessible through its own URL. For example, to include a script with the URL http://example.com/js/main.js, you can use the following code:
Yii::app()->clientScript->registerScriptFile("http://example.com/js/main.js");In order to control the place where a script will be inserted, you can pass one of the following constants as the second parameter:
|
Constants |
Description |
|---|---|
|
|
In the |
|
|
At the beginning of the |
|
|
At the end of the |
Core scripts are the ones bundled with Yii, such as jQuery. You can include a core script...