因此,我能够在我正在 yii 项目中处理的这个特定小部件之外加载大量其他脚本。甚至在小部件中,我也能够获得一个外部脚本来注册和加载。但是,当我尝试注册一个位于我的小部件资产文件夹中的脚本时,它注册得很好(如在var_dump(Yii::app()->clientScript)
调用中所见),但它永远不会加载到浏览器中。我重新启动了浏览器,但没有帮助,这是以下输出var_dump(Yii::app()->clientScript)
:
object(CClientScript)[10]
public 'enableJavaScript' => boolean true
public 'scriptMap' =>
array (size=0)
empty
public 'packages' =>
array (size=0)
empty
public 'corePackages' => null
public 'scripts' =>
array (size=1)
0 =>
array (size=2)
'jwplayer-licence-key' => string 'jwplayer.key = "8xU8+r4etXrBAwrr4Rzyq8niCsNZYC01/6XuUw==";' (length=58)
'jFileUploaderVars' => string 'var collegeId = 135717; var criteriaId = 0; var cameraMarkup = "<camera id="kdgtestcam" data-uuid="f89aee90-f319-0130-b0ac-12313940240c" data-videobitrate="131072" />";' (length=168)
protected 'cssFiles' =>
array (size=2)
'/ednet/css/bootstrap.min.css' => string '' (length=0)
'/ednet/css/font-awesome/css/font-awesome.min.css' => string '' (length=0)
protected 'scriptFiles' =>
array (size=2)
0 =>
array (size=4)
'/ednet/js/jquery-2.0.3.min.js' => string '/ednet/js/jquery-2.0.3.min.js' (length=29)
'/ednet/js/jwplayer/jwplayer.js' => string '/ednet/js/jwplayer/jwplayer.js' (length=30)
'/ednet/assets/6adc18e6/jfileuploader.js' => string '/ednet/assets/6adc18e6/jfileuploader.js' (length=39)
'//cameratag.com/1.8/cameratag.js' => string '//cameratag.com/1.8/cameratag.js' (length=32)
2 =>
array (size=2)
'/ednet/js/bootstrap.min.js' => string '/ednet/js/bootstrap.min.js' (length=26)
'/ednet/js/profileDisplay.js' => string '/ednet/js/profileDisplay.js' (length=27)
protected 'metaTags' =>
array (size=0)
empty
protected 'linkTags' =>
array (size=0)
empty
protected 'css' =>
array (size=0)
empty
protected 'hasScripts' => boolean true
protected 'coreScripts' =>
array (size=0)
empty
public 'coreScriptPosition' => int 0
public 'defaultScriptFilePosition' => int 0
public 'defaultScriptPosition' => int 4
private '_baseUrl' => null
public 'behaviors' =>
array (size=0)
empty
private '_initialized' (CApplicationComponent) => boolean true
private '_e' (CComponent) => null
private '_m' (CComponent) => null
这是我的代码:
WIDGET:
class JFileUploader extends CWidget {
public $fileTypes;
public $controller;
public $model;
public $criteria;
public function run() {
$this->registerClientScripts();
echo $this->render('_jfileuploader', array('model' => $this->model, 'criteria' => $this->criteria, 'controller' => $this->controller, 'fileTypes' => $this->fileTypes), true);
}
public function registerClientScripts() {
$assets = dirname(__FILE__) . '/assets';
$baseUrl = Yii::app()->assetManager->publish($assets);
$cs = Yii::app()->getClientScript();
$cs->registerScript('jFileUploaderVars', 'var collegeId = ' . $this->criteria['college_id'] . '; var criteriaId = ' . $this->criteria['criteria_id'] . '; var cameraMarkup = "' . CHtml::tag('camera', array('id' => Yii::app()->params['cameraTag-camera'], 'data-uuid' => Yii::app()->params['cameraTag-uuid'], 'data-videobitrate' => 131072)) . '";', CClientScript::POS_HEAD);
$cs->registerScriptFile($baseUrl . '/jfileuploader.js', CClientScript::POS_HEAD);
$cs->registerScriptFile('//cameratag.com/1.8/cameratag.js', CClientScript::POS_HEAD);
}
}
小部件按原样显示唯一我无法工作的是要在浏览器中加载的jfileuploader.js
文件和jFileUploaderVars
脚本。Note:
将加载的外部脚本是registerClientScripts()
方法中的最后一行。上面的两个就不会了。任何帮助将不胜感激!