【问题标题】:Yii Bootstrap not loading JS filesYii Bootstrap 不加载 JS 文件
【发布时间】:2013-02-28 04:15:42
【问题描述】:

我在我全新的 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() not found 错误。就像没有注册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',
            ),

有什么建议吗?

【问题讨论】:

    标签: twitter-bootstrap yii yii-extensions


    【解决方案1】:

    您必须专门注册 css 和 js:

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

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

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

    p>

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

    【讨论】:

    • 是的,为什么这里没有提到?谢谢,我试试看。
    【解决方案2】:
    <?php Yii::app()->bootstrap->registerAllCss(); ?>
    
    <?php Yii::app()->bootstrap->registerCoreScripts(); ?>
    <?php Yii::app()->clientScript->registerCssFile(Yii::app()->request->baseUrl.'/css/styles.css'); ?>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-12-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多