Yii在控制器中对视图js的控制

2017-01-13 10:53:03来源:csdn作者:wide288人点击

第七城市


//YIIframework路径



Yii::getFrameworkPath();



//protected/runtime


Yii::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');<?phpecho$this->module->assetsUrl;?>/css/main.css


Yii::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','varchart;');


$cs->registerScript('f2','varnewValueAxis;');


$cs->registerScript('f3','varaddAxis;');


$cs->registerScript('f4','varremoveAxis;');


$cs->registerScript('f5','chart=newAmCharts.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;



//得到当前url


Yii::app()->request->url;



//得到当前homeurl


Yii::app()->homeUrl;



//得到当前returnurl


Yii::app()->user->returnUrl



//项目路径


dirname(Yii::app()->BasePath);



//createUrl


$this->createUrl('urlBoyLeeTest');



#成功信息提示


Yii::app()->user->setFlash('success',"Thinkssavedsuccess!");



#错误信息提示


Yii::app()->user->setFlash('error',"herehasanError,Pleasecheckthat!");



#一般消息信息提示Yii::app()->user->setFlash('notice',"messgehere");
第七城市

最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台