Yii中gii在中文路径时的问题

来源:互联网 发布:ai聊天机器人源码 编辑:程序博客网 时间:2024/05/17 01:28

一开始觉得很奇怪,当我把同样的代码放入“快盘”,并将快盘下的一个子目录作为虚拟目录链接到IIS后,结果Yii的Gii无法显示代码模板。通过查看源文件,说明<select>的<option>中,value属性值正常,但后面的显示部分没有。当然,尽管没有显示模板路径,选择“空白”后仍然可以正常生成代码,但总是不爽。


搜索 gii目录下所有字符串“template”,可以找出不少,但最值得查看的是gii\views\common\generator.php中:

<div class="row template sticky">
 <?php echo $this->labelEx($model,'template'); ?>
 <?php echo $this->dropDownList($model,'template',$templates); ?>
 <div class="tooltip">
  Please select which set of the templates should be used to generated the code.
 </div>
 <?php echo $this->error($model,'template'); ?>
</div>

以上部分和源码对应,也可以看出下拉列表的数据来自变量$templates,那要查看有没有render(....,  array('templates' => ..))

可以发现 gii\CCodeForm.php中的代码:

 public function run()
 {
  $templates=array();
  foreach($this->model->getTemplates() as $i=>$template)
   $templates[$i]=basename($template).' ('.$template.')';

  $this->renderFile(Yii::getPathOfAlias('gii.views.common.generator').'.php',array(
   'model'=>$this->model,
   'templates'=>$templates,
  ));

  parent::run();

  echo "</div>";
 }

  foreach($this->model->getTemplates() as $i=>$template)

  $templates[$i]=basename($template).' ('.$template.')';

改写成 

  foreach($this->model->getTemplates() as $i=>$template) { file_put_contents('D:\ttt.txt',  $i.'-'.$template);
   $templates[$i]=basename($template).' ('.$template.')';

}

通过试验发现  $i 和 $template 可以正常获取值,这时才突然意识到 $template中含中文字符可能有问题

最后把快盘的根目录“D:\快盘”重命名成"D:\KuaiPan",重新设定快盘同步目录问题解决。当然,这可能是我使用

windows系统导致的,因为windows默认GBK编码,而Linux默认就是UTF-8编码


0 0
原创粉丝点击