《PHP编程:Yii控制器中操作视图js的方法》要点:
本文介绍了PHP编程:Yii控制器中操作视图js的方法,希望对您有用。如果有疑问,可以联系我们。
相关主题:YII框架
本文实例讲述了Yii控制器中操作视图js的方法.分享给大家供大家参考,具体如下:PHP教程
//YII framework路径 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'); <?php echo$this->module->assetsUrl; ?>/css/main.css Yii::app()->clientScript->registerCoreScript('jquery');
也可以如下方式(推荐):PHP教程
//注册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;');
转载请注明本页网址:
http://www.vephp.com/jiaocheng/5897.html