最新消息: 新版網站上線了!!!

Yii在控制器中對視圖js的控制


//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');

 

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

//注冊JS代碼:

  1.    

  2. $cs = Yii::app()->getClientScript(); 

  3. //注冊JS文件 

  4. $cs->registerScriptFile('js/amcharts/javascript/amcharts.js', CClientScript::POS_HEAD);    

  5. $cs->registerScriptFile('js/amcharts/javascript/raphael.js', CClientScript::POS_HEAD); 

  6. //注冊JS代碼 

  7. $cs->registerScript('f1','var chart;');    

  8. $cs->registerScript('f2','var newValueAxis;');    

  9. $cs->registerScript('f3','var addAxis;');    

  10. $cs->registerScript('f4','var removeAxis;');    

  11. $cs->registerScript('f5','chart = new AmCharts.AmSerialChart();');    

  12. $cs->registerScript('f6','chart.pathToImages = "images/amcharts/";');    

  13. $cs->registerScript('f7','chart.addListener("dataUpdated");');    

  14. $cs->registerScript('f9','chart.marginLeft = 80;');    

  15. $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; 

 

//得到當前home url

Yii::app()->homeUrl;

 

//得到當前return url

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

 

轉載請注明:谷谷點程序 » Yii在控制器中對視圖js的控制

体彩25选5开奖号码