Yii Tutorial : How to Add JavaScript into your views ?

This post is about registering inline and external javascript files into views, Yii provided CClientScript to manage the scripts and CSS files in Yii application.

How to Register or add External java script files :

Here Script file located at webroot/resources/js., Yii::app()->baseUrl will return app base url.

How to Register or add inline java script:

Script Positions

CClientScript::POS_HEAD: The script is inserted in the head section right before the title element.
CClientScript::POS_BEGIN: The script is inserted at the beginning of the body section.
CClientScript:: POS_END: The script is inserted at the end of the body section.
CClientScript::POS_LOAD: The script is inserted in the window.onload() function.
CClientScript::POS_READY: The script is inserted in the jQuery’s ready function.

I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.

I am Arjun from Hyderabad (India). I have been working as a software engineer from last 7+ years, and its my passion to learn new things and implement them as a practice. Aside from work, I likes gardening and spending time with pets.
DMCA.com Protection Status