Yii-Bootstrap Don't Work For Me.

Hello :)

So, before, you have to know that I am newbie with Yii.

Then, t’day, I tried to use Bootstrap with Yii, I followed all what is written on the Setup page of Yii-bootstrap, but it doesn’t work with me!

I don’t get any error, it’s just that the stylesheet is not applied…I tried some code source from the Docs but without success!

Thanks for your help :)

Hi there

can you post some code

Make sure you have this line in the main layout:


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

Hi there :)

So, here’s my files:

config/main.php :


<?php


// uncomment the following to define a path alias

// Yii::setPathOfAlias('local','path/to/local-folder');


Yii::setPathOfAlias('bootstrap', dirname(__FILE__).'/../extensions/bootstrap');


// This is the main Web application configuration. Any writable

// CWebApplication properties can be configured here.

return array(

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

	'name'=>'My Web Application',


	// preloading 'log' component

	'preload'=>array('log'),


	// autoloading model and component classes

	'import'=>array(

		'application.models.*',

		'application.components.*',

	),


	'modules'=>array(

		// uncomment the following to enable the Gii tool

		

		'gii'=>array(

			'class'=>'system.gii.GiiModule',

			'password'=>'gii',

			// If removed, Gii defaults to localhost only. Edit carefully to taste.

			'ipFilters'=>array('127.0.0.1','::1'),

		),

		

	),


	// application components

	'components'=>array(

		'user'=>array(

			// enable cookie-based authentication

			'allowAutoLogin'=>true,

		),

		// uncomment the following to enable URLs in path-format

		

		'urlManager'=>array(

			'urlFormat'=>'path',

			'rules'=>array(

				'<controller:\w+>/<id:\d+>'=>'<controller>/view',

				'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',

				'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',

			),

		),

		

		/*'db'=>array(

			'connectionString' => 'sqlite:'.dirname(__FILE__).'/../data/testdrive.db',

		),*/

		// uncomment the following to use a MySQL database

		

		'db'=>array(

			'connectionString' => 'mysql:host=localhost;dbname=test',

			'emulatePrepare' => true,

			'username' => 'root',

			'password' => '',

			'charset' => 'utf8',

		),

		

		'errorHandler'=>array(

			// use 'site/error' action to display errors

			'errorAction'=>'site/error',

		),

		'log'=>array(

			'class'=>'CLogRouter',

			'routes'=>array(

				array(

					'class'=>'CFileLogRoute',

					'levels'=>'error, warning',

				),

				// uncomment the following to show log messages on web pages

				/*

				array(

					'class'=>'CWebLogRoute',

				),

				*/

			),

		),

	),


	// application-level parameters that can be accessed

	// using Yii::app()->params['paramName']

	'params'=>array(

		// this is used in contact page

		'adminEmail'=>'webmaster@example.com',

	),

	


);


	//Boostrap!==>

	return array(

    'theme'=>'bootstrap', // requires you to copy the theme under your themes directory

    'modules'=>array(

        'gii'=>array(

            'generatorPaths'=>array(

                'bootstrap.gii',

            ),

        ),

    ),

    'components'=>array(

        'bootstrap'=>array(

            'class'=>'bootstrap.components.Bootstrap',

        ),

    ),

);

And when I tried this following code, on the index page, just for testing, it didn’t work (the stylesheet wasn’t applied):




<?php $this->widget('bootstrap.widgets.TbButtonGroup', array(

    'buttons'=>array(

        array('label'=>'1', 'url'=>'#'),

        array('label'=>'2', 'url'=>'#'),

        array('label'=>'3', 'url'=>'#'),

        array('label'=>'4', 'url'=>'#'),

    ),

)); ?>



Hi.

I did so, and I got this CException:


Property "CWebApplication.bootstrap" is not defined.

Thanks for your help guys:)

andy_s he has already done the ext registration in his config

i_can can you see the bootstrap css file in your html page do view source and double check please

Hi :)

I checked the source page, and it seems like that the bootstrap css file is not loaded at all.

Here’s the head bloc code:




<head>

	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

	<meta name="language" content="en" />


	<!-- blueprint CSS framework -->

	<link rel="stylesheet" type="text/css" href="/YiiTest/css/screen.css" media="screen, projection" />

	<link rel="stylesheet" type="text/css" href="/YiiTest/css/print.css" media="print" />

	<!--[if lt IE 8]>

	<link rel="stylesheet" type="text/css" href="/YiiTest/css/ie.css" media="screen, projection" />

	<![endif]-->


	<link rel="stylesheet" type="text/css" href="/YiiTest/css/main.css" />

	<link rel="stylesheet" type="text/css" href="/YiiTest/css/form.css" />


	<title>WebLib</title>

</head>



have you already tried this?

Yii.Booster.Getting.Started

hope it help you

~Happy Coding~

Though it is too late but for the reference of new comers

your protected\config\main.php need only one return. after adding bootstrap extension it will look like this




<?php


// uncomment the following to define a path alias

// Yii::setPathOfAlias('local','path/to/local-folder');

Yii::setPathOfAlias('bootstrap', dirname(__FILE__) . '/../extensions/bootstrap');


// This is the main Web application configuration. Any writable

// CWebApplication properties can be configured here.

return array(

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

    'name' => 'Contacts',

    // preloading 'log' component

    'preload' => array('log'),

    // autoloading model and component classes

    'import' => array(

        'application.models.*',

        'application.components.*',

    ),

    'modules' => array(

        // uncomment the following to enable the Gii tool


        'gii' => array(

            'class' => 'system.gii.GiiModule',

            'password' => 'yourPasswordHere',

            // If removed, Gii defaults to localhost only. Edit carefully to taste.

            'ipFilters' => array('127.0.0.1', '::1'),

            'generatorPaths' => array(

                'bootstrap.gii',

            ),

        ),

    ),

    // application components

    'components' => array(

        'user' => array(

            // enable cookie-based authentication

            'allowAutoLogin' => true,

        ),

        'bootstrap' => array(

            'class' => 'bootstrap.components.Bootstrap',

        ),

        // uncomment the following to enable URLs in path-format

        /*

          'urlManager'=>array(

          'urlFormat'=>'path',

          'rules'=>array(

          '<controller:\w+>/<id:\d+>'=>'<controller>/view',

          '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',

          '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',

          ),

          ),

         */


        // database settings are configured in database.php

        'db' => require(dirname(__FILE__) . '/database.php'),

        'errorHandler' => array(

            // use 'site/error' action to display errors

            'errorAction' => 'site/error',

        ),

        'log' => array(

            'class' => 'CLogRouter',

            'routes' => array(

                array(

                    'class' => 'CFileLogRoute',

                    'levels' => 'error, warning',

                ),

            // uncomment the following to show log messages on web pages

            /*

              array(

              'class'=>'CWebLogRoute',

              ),

             */

            ),

        ),

    ),

    // application-level parameters that can be accessed

    // using Yii::app()->params['paramName']

    'params' => array(

        // this is used in contact page

        'adminEmail' => 'webmaster@example.com',

    ),

    'theme' => 'bootstrap', // requires you to copy the theme under your themes directory

);




in case you didn’t choose bootstrap as your theme then in your views\layouts\main.php add following line


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

and finally use bootstrap widgets




 <?php $this->widget('bootstrap.widgets.TbButton', array(

    'label'=>'Primary',

    'type'=>'primary', // null, 'primary', 'info', 'success', 'warning', 'danger' or 'inverse'

    'size'=>'large', // null, 'large', 'small' or 'mini'

)); ?>