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 ");