首页 > 语言 > PHP > 正文

Yii控制器中操作视图js的方法

2024-05-04 23:47:37
字体:
来源:转载
供稿:网友

本文实例讲述了Yii控制器中操作视图js的方法。分享给大家供大家参考,具体如下:

//YII framework路径Yii::getFrameworkPath();//protected/runtimeYii::app()->getRuntimePath();//protected/venders目录Yii::import('application.venders.*');//或在protected/config/main.php说明'import'=>array(  //......  'application.venders.*',),//插入meta信息Yii::app()->clientScript->registerMetaTag('keywords','关键字');Yii::app()->clientScript->registerMetaTag('description','一些描述');Yii::app()->clientScript->registerMetaTag('author','作者');//如何在控制器添加CSS文件或JavaScript文件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.cssYii::app()->clientScript->registerCoreScript('jquery');

也可以如下方式(推荐):

//注册JS代码:$cs = Yii::app()->getClientScript();//注册JS文件$cs->registerScriptFile('js/amcharts/javascript/amcharts.js', CClientScript::POS_HEAD);$cs->registerScriptFile('js/amcharts/javascript/raphael.js', CClientScript::POS_HEAD);//注册JS代码$cs->registerScript('f1','var chart;');$cs->registerScript('f2','var newValueAxis;');$cs->registerScript('f3','var addAxis;');$cs->registerScript('f4','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('f10','chart.marginRight = 50;');
//在view中得到当前controller的ID方法:Yii::app()->getController()->id;//在view中得到当前action的ID方法Yii::app()->getController()->getAction()->id;//yii获取ip地址Yii::app()->request->userHostAddress;//yii判断提交方式Yii::app()->request->isPostRequest;//得到当前域名:Yii::app()->request->hostInfo;//得到proteced目录的物理路径YII::app()->basePath;//获得上一页的url以返回Yii::app()->request->urlReferrer;//得到当前urlYii::app()->request->url;//得到当前home urlYii::app()->homeUrl;//得到当前return urlYii::app()->user->returnUrl//项目路径dirname(Yii::app()->BasePath);//create Url$this->createUrl('urlBoyLeeTest');# 成功信息提示Yii::app()->user->setFlash('success', "Thinks saved success!");# 错误信息提示Yii::app()->user->setFlash('error', "here has an Error, Please check that!");# 一般消息信息提示Yii::app()->user->setFlash('notice', "messge here");


注:相关教程知识阅读请移步到PHP教程频道。
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表

图片精选