Method for operating view js in Yii controller, yii controller view js

Source: Internet
Author: User

Method for operating view js in Yii controller, yii controller view js

This article describes how to operate view js in Yii controller. We will share this with you for your reference. The details are as follows:

// YII framework path Yii: getFrameworkPath (); // protected/runtimeYii: app ()-> getRuntimePath (); // protected/venders directory Yii :: import ('application. venders. * '); // or in protected/config/main. php description 'import' => array (//...... 'application. venders. * ',), // insert meta information. Yii: app ()-> clientScript-> register1_ag ('keyword', 'key'); Yii: app () -> clientScript-> registerMetaTag ('description', 'some description'); Yii: app ()-> clientScript-> registerMet ATag ('author', 'author '); // how to add a CSS file or JavaScript file in the Controller Yii: app ()-> clientScript-> registerCssFile (Yii :: app ()-> baseUrl. '/css/my.css'); Yii: app ()-> clientScript-> registerScriptFile (Yii: app ()-> baseUrl. '/css/my. js'); <? Php echo $ this-> module-> assetsUrl;?> /Css/main.css Yii: app ()-> clientScript-> registerCoreScript ('jquery ');

You can also use the following method (recommended ):

// Register the JS Code: $ cs = Yii: app ()-> getClientScript (); // register the JS File $ cs-> registerScriptFile ('js/amcharts/javascript/amcharts. js', CClientScript: POS_HEAD); $ cs-> registerScriptFile ('js/amcharts/javascript/raphael. js', CClientScript: POS_HEAD); // register the js Code $ cs-> registerScript ('f1', 'var chart ;'); $ cs-> registerScript ('F2', 'var newValueAxis; '); $ cs-> registerScript ('f3', 'var addAxis ;'); $ cs-> registerScript ('f1', 'var removeAxis; '); $ cs-> registerScript ('f5', 'chart = new AmCharts. amSerialChart (); '); $ cs-> registerScript ('f6', 'chart. pathToImages = "images/amcharts/"; '); $ cs-> registerScript ('f7', 'chart. addListener ("dataUpdated"); '); $ cs-> registerScript ('f9', 'chart. marginLeft = 80; '); $ cs-> registerScript ('F3', 'chart. marginRight = 50 ;');
// Obtain the ID method of the current controller in view: Yii: app ()-> getController ()-> id; // obtain the ID method of the current action in view. Yii:: app ()-> getController ()-> getAction ()-> id; // yii obtain the IP address Yii: app ()-> request-> userHostAddress; // yii judgment submission method Yii: app ()-> request-> isPostRequest; // obtain the current domain name: Yii: app ()-> request-> hostInfo; // obtain the physical path YII: app ()-> basePath of the proteced directory; // obtain the url of the previous page to return Yii: app ()-> request-> urlReferrer; // obtain the current urlYii: app ()-> request-> url; // obtain the current home urlYii :: App ()-> homeUrl; // get the current return urlYii: app ()-> user-> returnUrl // project path dirname (Yii: app () -> BasePath); // create Url $ this-> createUrl ('urlboyleetest '); # Success message: Yii: app () -> user-> setFlash ('success ', "Thinks saved success! "); # Error message: Yii: app ()-> user-> setFlash ('error'," here has an Error, Please check that! "); # General message prompt Yii: app ()-> user-> setFlash ('notice '," messge here ");

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.