Yii Bootstrap 不加载 JS 文件 [英] Yii Bootstrap not loading JS files

查看:32
本文介绍了Yii Bootstrap 不加载 JS 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我全新的 Yii 项目中使用 Yii-Bootstrap.我完全按照安装说明进行操作.

I'm using Yii-Bootstrap in my brand new Yii project. I followed the install instructions exactly.

在首页我使用的是 JS Carousel 插件.

On the front page I am using the JS Carousel plugin.

$this->widget('bootstrap.widgets.TbCarousel', array(
    'items'=>array(
        array(
            'image'=>'http://placehold.it/770x400&text=First+thumbnail',
            'label'=>'asdf',
            'caption'=>'Cras justo odio, '
        ),
        array(
            'image'=>'http://placehold.it/770x400&text=Second+thumbnail',
            'label'=>'asdf',
            'caption'=>'Cras justo odio, '
        ),
        array(
            'image'=>'http://placehold.it/770x400&text=Third+thumbnail',
            'label'=>'asdf',
            'caption'=>'Cras justo odio, '
        ),
    ),
));

未捕获的类型错误:对象 [object Object] 没有方法 'carousel'

这会导致 .carousel() not found 错误.就像 JS 文件没有被注册.CSS 和一切看起来都很好.

This leads to a .carousel() not found error. It's like the JS files are not being registered. The CSS and everything looks fine.

我正在使用 yii-environment 扩展..

I'm using the yii-environment extension..

return array(

    // Set yiiPath (relative to Environment.php)
    'yiiPath' => dirname(__FILE__) . '/../../../yii-1.1.13/framework/yii.php',
    'yiicPath' => dirname(__FILE__) . '/../../../yii-1.1.13/framework/yiic.php',
    'yiitPath' => dirname(__FILE__) . '/../../../yii-1.1.13/framework/yiit.php',

    // Static function Yii::setPathOfAlias()
    'yiiSetPathOfAlias' => array(
        // uncomment the following to define a path alias
        'bootstrap' => realpath(dirname(__FILE__).'/../extensions/bootstrap')
    ),

    // This is the main Web application configuration. Any writable
    // CWebApplication properties can be configured here.
    'configWeb' => array(

        'basePath' => dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
            'theme' => 'bootstrap',

        // Preloading 'log' component
        'preload' => array('log'),

        // Autoloading model and component classes
        'import' => array(
            'application.models.*',
            'application.components.*',
        ),

        // Application components
        'components' => array(
            'bootstrap'=>array(
                'class'=>'bootstrap.components.Bootstrap',
            ),

有什么建议吗?

推荐答案

你需要专门注册 css 和 js:

You will have to register the css and js specifically:

Yii::app()->bootstrap->register();

这与旧版扩展中的做法不同.我不知道为什么在任何地方的文档中都没有提到这一点.

which is different from the way it was done in older versions of the extension. I do not know why this is not mentioned in the documentation anywhere.

将上面这行代码放在你的布局中的一个好地方,如果你的整个站点/应用程序使用 yii-bootstrap,或者如果你只在特定的视图中这样做,你可以将它放在那些视图中.

A good place to put the above line of code is in your layout, if your entire site/app uses yii-bootstrap, or if you are doing it in only specific views, you can put it in those views.

P.S - 您可以在 bootstrap/components/Bootstrap.php 文件中找到该函数.

P.S - You can find the function in the bootstrap/components/Bootstrap.php file.

这篇关于Yii Bootstrap 不加载 JS 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆