douwei9759 2013-10-01 20:54
浏览 64

Yii - 脚本文件注册但从未在浏览器中加载

So I am able to load a boat load of other scripts outside of this particular widget that i'm working on in a yii project. and even in the widget i am able to get an external script to register and load. However when i attempt to register a script that is in my widget's assets folder it registers just fine (as seen in a var_dump(Yii::app()->clientScript) call) but it never loads in the browser. I have restarted my browser and that didn't help, here is the output of 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

and here is my code: 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);
    }
  }

the widget displays just as it should the only thing that i can't get to work is the jfileuploader.js file and the jFileUploaderVars script to load in the browser. Note: the external script that will load is the last line in the registerClientScripts() method. the two above it will not. any help would be greatly appreciated!

  • 写回答

1条回答 默认 最新

  • dongzhi8984 2013-10-01 21:22
    关注

    I am not sure but give a try to

    Yii::app()->assetManager->publish(Yii::getPathOfAlias('ext.mywidget.assets'),...);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示