yiisoft / yii2

Yii 2: The Fast, Secure and Professional PHP Framework
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
14.24k stars 6.91k forks source link

registerCssFile invalid in yii\base\view #110

Closed netyum closed 11 years ago

netyum commented 11 years ago

Either in controller ($this->view->registerCssFile), widgets( same controller) and view(this->registerCssFile);

the layout master view added beginPage / endPage

qiangxue commented 11 years ago

What is the issue? Tried putting the code in controller, but no problem. Please describe the steps to reproduce the issue.

netyum commented 11 years ago

ok.qiang. chinese.

直接在controller的action中添加一行注册

    public function actionIndex()
    {
        $this->view->registerCssFile('http://www.yiibook.com/themes/classic/css/yiibook.css');

并且在layout中使用

<?php
$this->beginPage();
?>
HTML/HEAD/BODY/....
<?php
$this->endPage();
?>

显示页面时,并未找到 注册的css

还有在yii\base\View类中,743行左右

    protected function renderHeadHtml()
    {   
        $lines = array();
        if (!empty($this->metaTags)) {
            $lines[] = implode("\n", $this->cssFiles);
        }   
        if (!empty($this->linkTags)) {
            $lines[] = implode("\n", $this->cssFiles);
        }   
        if (!empty($this->cssFiles)) {
            $lines[] = implode("\n", $this->cssFiles);
        }   
      ...

上面的linkTags metaTags 后面用的都是cssFiles,应该是复制的问题。

qiangxue commented 11 years ago

Thanks! I have fixed the issue you described. For the layout view, you need to add $this->head() in the layout. Please refer to the "app" example.

netyum commented 11 years ago

ok.thanks.