Yii Bootstrap没有加载JS文件

时间:2013-02-28 04:15:43

标签: twitter-bootstrap yii yii-extensions

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

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

$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, '
        ),
    ),
));

Uncaught TypeError: Object [object Object] has no method 'carousel'

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

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

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',
            ),

有什么建议吗?

2 个答案:

答案 0 :(得分:4)

您必须具体注册css和js:

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

与旧版扩展程序中的方式不同。我不知道为什么在文档中没有提到这一点。

如果您的整个网站/应用程序使用yii-bootstrap,或者如果您只在特定视图中执行此操作,那么放置上述代码行的好地方就在您的布局中。您可以将它放在这些视图中。

P.S - 您可以在 bootstrap / components / Bootstrap.php 文件中找到该功能。

答案 1 :(得分:-1)

<?php Yii::app()->bootstrap->registerAllCss(); ?>

<?php Yii::app()->bootstrap->registerCoreScripts(); ?>
<?php Yii::app()->clientScript->registerCssFile(Yii::app()->request->baseUrl.'/css/styles.css'); ?>
相关问题