[EXTENSION] Bootstrap

1stly, i like to thanks for such a great ext !

Here I am trying to archive calling remote url in modal popup. I am searching around and have not found an good link to go…

In twitter boostrap document state:

But i failed to load my url (create form) while i do in yii boostrap ext below is my code:




<?php $this->beginWidget('bootstrap.widgets.TbModal', array('id'=>'myModal')); ?>

<div class="modal-header">

    <a class="close" data-dismiss="modal">&times;</a>

    <h4>Modal header</h4>

</div>

<div class="modal-body">

    <p> Modal body </p>

</div>

<div class="modal-footer">

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

        'type'=>'primary',

        'label'=>'Save changes',

    )); ?>

</div> 

<?php $this->endWidget(); ?>


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

    'label'=>'New Project',

    'type'=>'primary',

    'url'=>$this->createUrl('create'), // My Remote URL

    'htmlOptions'=>array(

        'data-toggle'=>'modal',

        'data-target'=>'#myModal',

     ), 

)); ?>



Appreciate any help.

Regards,

pod2g

I’m having trouble with the scrollspy attribute for bootstrap.widgets.TbMenu.

It says it takes either a string or an array, but it’s not working when I feed it an array.

This works:


<?php

  $this->widget('bootstrap.widgets.TbNavbar', array(

      

      ...

    

    'items' => array(

      array(

        'scrollspy' => '.navbar',

        'class' => 'bootstrap.widgets.TbMenu',

        'items' => array(

          

          ...

          

        ),

      ),

    ),

  ));

?>

This doesn’t:


<?php

  $this->widget('bootstrap.widgets.TbNavbar', array(

      

      ...

    

    'items' => array(

      array(

        'scrollspy' => array('selector'=>'.navbar'),

        'class' => 'bootstrap.widgets.TbMenu',

        'items' => array(

          

          ...

          

        ),

      ),

    ),

  ));

?>

The reason I want to use an array is so that I can specify an offset.

Yii-Bootstrap is working, but i’m not able to get working the gii code generation

I’ve extracted extension into extensions/bootstrap

Added




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



Then

into modules’s gii config




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

'password' => 'develop',

'generatorPaths' => array(

        'bootstrap.gii' ,

)



But when I open GII CRUD generator, i can see only the code generator. Why ?!

If I remember correctly you need to use "spy" instead of "selector".

Cheers, Felipe

Coincidentally I just implemented another scrollspy in one of my projects, too.

It seems, the option’s name has been changed in the meantime.

Instead of "selector" (and "spy"), please use "target".

[color="#1C2837"][size="2"]Anybody have any idea why the dropdown menus in the navbar will work on every page except the home page? I even copied the example [/size][/color]

[color="#1C2837"][size="2"]




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

    'type'=>'inverse', // null or 'inverse'

    'brand'=>'Project name',

    'brandUrl'=>'#',

    'collapse'=>true, // requires bootstrap-responsive.css

    'items'=>array(

        array(

            'class'=>'bootstrap.widgets.TbMenu',

            'items'=>array(

                array('label'=>'Home', 'url'=>'#', 'active'=>true),

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

                array('label'=>'Dropdown', 'url'=>'#', 'items'=>array(

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

                    array('label'=>'Another action', 'url'=>'#'),

                    array('label'=>'Something else here', 'url'=>'#'),

                    '---',

                    array('label'=>'NAV HEADER'),

                    array('label'=>'Separated link', 'url'=>'#'),

                    array('label'=>'One more separated link', 'url'=>'#'),

                )),

            ),

        ),

        '<form class="navbar-search pull-left" action=""><input type="text" class="search-query span2" placeholder="Search"></form>',

        array(

            'class'=>'bootstrap.widgets.TbMenu',

            'htmlOptions'=>array('class'=>'pull-right'),

            'items'=>array(

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

                array('label'=>'Dropdown', 'url'=>'#', 'items'=>array(

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

                    array('label'=>'Another action', 'url'=>'#'),

                    array('label'=>'Something else here', 'url'=>'#'),

                    '---',

                    array('label'=>'Separated link', 'url'=>'#'),

                )),

            ),

        ),

    ),

)); ?>

[/size][/color]

[color="#1C2837"][size=“2”]into my homepage and the dropdowns won’t work.[/size][/color]

[color="#1C2837"][size="2"]Confused. [/size][/color]

how can i use it with giix? thanks

Hi!

I cannot get bootstap working.

I have downloaded latest Yii (1.1.13…).

I have opened demo blog.

I have created "extensions/bootstrap" and "themes" folders.

I have downloaded latest bootstrap and unziped it into extensions/bootstrap.

Also I have copied theme folder to themes and renamed it to "bootstrap".

I have configure my main.config:





<?php


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


return array(

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

	'name'=>'Yii Blog Demo',


	// preloading 'log' component

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


	// autoloading model and component classes

	'import'=>array(

		'application.models.*',

		'application.components.*',

	),


	'defaultController'=>'post',

    'theme'=>'bootstrap', 

    

    /*'modules'=>array(

        'gii'=>array(

            'generatorPaths'=>array(

                'bootstrap.gii',

            ),

        ),

    ),*/


	// application components

	'components'=>array(

        'bootstrap'=>array(

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

        ),

		'user'=>array(

			// enable cookie-based authentication

			'allowAutoLogin'=>true,

		),

		'db'=>array(

			//'connectionString' => 'sqlite:protected/data/blog.db',

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

			'emulatePrepare' => true,

            'username' => 'root',

            'password' => '',

            'charset' => 'utf8',

            'tablePrefix' => 'tbl_',

		),

		'errorHandler'=>array(

			'errorAction'=>'site/error',

		),

		'urlManager'=>array(

			'urlFormat'=>'path',

			'rules'=>array(

				'post/<id:\d+>/<title:.*?>'=>'post/view',

				'posts/<tag:.*?>'=>'post/index',

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

			),

		),

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

				),

				*/

			),

		),

	),

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

);




Then I open website, no errors appear, but also no bootstrap. Nothing has changed.

Can you guide me, please, how to understand why nothing happens?

Hello,

I use the TbActivForm Widget for a lot of textfields (see below). I’d like to arrange the textfields parallel (side by side).

My first Idea was a Table, but when i reduce the size of Firefox, the textfields aren’t adaptiv.


<?php /** @var BootActiveForm $form */

$form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(

    'id'=>'verticalForm',

    'htmlOptions'=>array('class'=>'well'),

)); ?>




<table>

<tr>

<td><?php echo $form->textFieldRow($model, 'Test', array('disabled'=>true)); ?></td>

<td><?php echo $form->textFieldRow($model, 'Test2', array('disabled'=>true)); ?></td>

<td><?php echo $form->textFieldRow($model, 'Test3', array('disabled'=>true));?></td>

</tr>

<tr>

<td><?php echo $form->textFieldRow($model, 'Test4', array('disabled'=>true)); ?></td>

<td><?php echo $form->textFieldRow($model, 'Test5', array('disabled'=>true)); ?></td>

<td><?php echo $form->textFieldRow($model, 'Test6', array('disabled'=>true)); ?></td>

</tr>

</table>


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

    'label'=>'Bearbeiten',

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

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

    'url'=>'index.php?r=site/test&id='.$model["ID"],


)); ?>

 </div>

<?php $this->endWidget(); ?>

Any solutions? :) Thanks.

Hello there!! Thanks for nice ext for Yii! I have few questions about new version (2.0):

  1. why i can’t set ‘responsiveCss’ to ‘false’ in ‘main’ config?! no init() method with params in new version Bootstrap class??

  2. i use CJuiDialog for some actions:




<?php

    $this->beginWidget('zii.widgets.jui.CJuiDialog', array(

    'id'=>'edit-dialog',

    'options'=>array(

    	'title'=>Yii::t('user', 'label_rename_file'),

        'autoOpen'=>false,

        'modal'=>true, /* this makes the dialog, appear on a overlay */

        'width'=>500,

        'height'=>280,

    	'minHeight'=>400,	

    	'autoOpen'=>false,

    	'bgiframe'=>true,

    	'draggable'=>true,

    	'resizable'=>true,

    	'closeOnEscape'=>true,

    ),

    ));

?>

<iframe id="edit-frame" width="100%" height="100%" scrolling="no"></iframe>

<?php $this->endWidget(); ?>


//CGridView action button

'buttons'=>array(

	    'update' => array(

	    	'label'=>Yii::t('user', 'label_rename'),

    		'url'=>'$this->grid->controller->createUrl("files/rename", array("id"=>$data->primaryKey,"asDialog"=>1,"gridId"=>$this->grid->id))',

    		'click'=>'function(){$("#edit-frame").attr("src",$(this).attr("href"));$("#edit-dialog").dialog("open");  return false;}',

),...



and when i use ‘iframe’ tag inside CJuiDialog widget Bootstrap not loaded!! In old version all works fine! And if we use ‘div’ tag all works fine too. But ‘iframe’… I think it because in new version we use ‘theme’? or i’m wrong?

Is there a way to user an other gridview into a relational table row ?

Help me please.

How to get or set value to ‘bootstrap.widgets.TbButtonGroup’ radio or checkbox

like a CHtml::checkBox

I got the same issue and after checking the original source code of extension i found out that "css and java script" including functions are changed. you need to put them in your LAYOUT [main.php] file:

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

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

i did the same and everything is working fine now.

with regards

Thanks all, i install success

The top fixed navbar covering content. Was able to fix adding 40px padding to the body, but when screen reduced to below 768px there is a huge gap in between. Google the problem and found that Im suppose to add this, but have no clue where. Everywhere i try, i don’t get the proper response.


body { padding-top: 40px; }

@media screen and (max-width: 768px) {

    body { padding-top: 0px; }

}

Did you check in logs if boostrap is loaded ?

You can try use in some view


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

I had some problems with bootstrap sometime ago and i used Yiibooster instead and it helped so maybe not the best idea but it could help.

Did You find any solution, or someone else did ?

Hello all,

It should go without saying that much thanks are due to Chris for his work on this extension. It’s amazing.

As many of you have probably already successfully done I’ve been struggling with creating Modal create/edit functionality using a combination of TbModal and TbGridView.

I have a add new feature working perfectly with validation using:

form:




<div class="form">

    <?php /** @var Server $model */

    /** @var AweActiveForm $form */ // <- extension is leveraging boostrap form

    $form = $this->beginWidget('ext.AweCrud.components.AweActiveForm', array(

    'id' => 'server-form',

    'enableAjaxValidation' => true,

    'enableClientValidation'=> true,

    //'clientOptions'=>array('validateOnSubmit'=>true),

    

    )); ?>


    <p class="note">

        <?= Yii::t('AweCrud.app', 'Fields with') ?> <span class="required">*</span>

        <?= Yii::t('AweCrud.app', 'are required') ?>.    </p>


    <?= $form->errorSummary($model) ?>


                        <?= $form->textFieldRow($model, 'asset_id', array('class' => 'span5', 'maxlength' => 20)) ?>

                        <?= $form->dropDownListRow($model, 'customer_id', CHtml::listData(Customer::model()->findAll(), 'id', Customer::representingColumn())) ?>

                        <?= $form->textFieldRow($model, 'hostname', array('class' => 'span5', 'maxlength' => 255)) ?>

                        <?= $form->textAreaRow($model,'description',array('rows'=>6, 'cols'=>50, 'class'=>'span5')) ?>

                        <?= $form->dropDownListRow($model, 'rack_id', CHtml::listData(Rack::model()->findAll(), 'id', Rack::representingColumn())) ?>

                        <?= $form->textFieldRow($model, 'serial_number', array('class' => 'span5', 'maxlength' => 20)) ?>

                       

                <div class="form-actions">

                <?php 

                

              //if ($model->isNewRecord)  

                //redirects on update modal

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

					'buttonType'=>'submit',

					'type'=>'primary',

					'label'=>$model->isNewRecord ? Yii::t('AweCrud.app', 'Create') : Yii::t('AweCrud.app', 'Save'),

				));


			//else

		?>

    </div>

    <?php $this->endWidget(); ?>

</div>



controller:




	public function actionCreate()

	{

		$model = new Server;

        $this->performAjaxValidation($model, 'server-form');

		if(isset($_POST['Server']))

		{

			$model->attributes = $_POST['Server'];

			if($model->save())

			{

              if (Yii::app()->request->isAjaxRequest)

                {

                    echo CJSON::encode(array(

                        'status'=>'success', 

                        'div'=>"Server successfully added"

                        ));

                    exit;               

                }

                else

                    $this->redirect(array('view','id'=>$model->id));         

			}

		}

		if (Yii::app()->request->isAjaxRequest)

        {

            echo CJSON::encode(array(

                'status'=>'failure', 

                'div'=>$this->renderPartial('_form', array('model'=>$model), true))); 

            exit;               

        }

        else $this->render('create',array('model'=>$model,)); 


	}



and a stand alone button and JS for it in the view:




<script type="text/javascript">

function addServer()

{

    <?php echo CHtml::ajax(array(

            'url'=>array('server/create'),

            'data'=> "js:$(this).serialize()",

            'type'=>'post',

            'dataType'=>'json',

            'success'=>"function(data)

            {

                if (data.status == 'failure')

                {

                    $('#addModal div.divForCreate').html(data.div);

                    // Here is the trick: on submit-> once again this function!

                    $('#addModal div.divForCreate form').submit(addServer);

                }

                else

                {

                    $('#addModal div.divForCreate').html(data.div);

                    $.fn.yiiGridView.update('server-grid');

                    setTimeout(\"$('#addModal').dialog('close') \",3000);

                }

            } ",

            ))?>;

    return false; 

}

</script>

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

        'label'=> 'Add Server',

    	'size' => 'small',

        'type'=>'primary',

        'htmlOptions'=>array(

                //'data-toggle'=>'modal',

        'url'=>'#',

        'data-target'=>'#addModal',

        'onclick'=>"{addServer(); $('#addModal').modal();}" 

        ),

)); ?>



This works perfectly, fields are validated and the controller returns success to the modal (I’ll add the closing later). What’s been causing me to bang my head is when I try to make the update modal work using:




	                'update'=>

	                    array(

	                        'url'=>'Yii::app()->createUrl("server/update", array("id"=>$data->id))',

	                        'options'=>array(

	                            'ajax'=>array(

	                                'type'=>'POST',

	                                'url'=>"js:$(this).attr('href')",

	                    			//'data'=> "js:$(this).serialize()",

	                    			'ajaxUrl' => 'Yii::app()->createUrl("server/update", array("id"=>$data->id))',		                   

	                                'dataType'=>'json',                            

	                                'success'=>'function(data){	  

	         			                 if (data.status == "success"){ 

	         			                 	alert(data);

								            $("#viewModal").modal("hide");

								           // $.fn.yiiGridView.update("server-grid");											            

								            setTimeout(function(){location.reload(true);},400);

            							 }else{           							 	

            							 	$("#viewModal .modal-body p ").html(data.div);

	                                		$("#viewModal").modal();

										 }}',

	                            ),

	                        ),

	                    ),




in a TbButtonColumn button declaration I can’t seem to keep the form from redirecting to the view on success or update form on validation fail.

Basically it seems like the button isn’t creating an ajax call and retrieving the data back into the success function for me to process.

Does anyone know what I’m missing? I’m sure it’s something easy that I’m overlooking but I tried everything from hunting down every attribute I could think of on the button and going as far as creating another button on the form.

Any help would be wonderful!

Thanks for reading and thanks for a wonderful extension.

I don’t know if this will help you but I’ve found that when I used CJuiDialog directly with bootstrap I’ve had issues with JQuery. You might want to consider refactoring the dialog using the bootstrap provided TbModal:





<!-- View/update Popup  -->

<?php $this->beginWidget('bootstrap.widgets.TbModal', array('id'=>'viewModal')); ?>

<!-- Popup Header -->

<div class="modal-header">

<h4>Details</h4>

</div>

<!-- Popup Content -->

<div class="modal-body">

<p>Details</p>

<div class="divForForm"></div>

</div>

<!-- Popup Footer -->

<div class="modal-footer">

<!-- close button -->

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

    'label'=>'Close',

    'url'=>'#',

    'htmlOptions'=>array('data-dismiss'=>'modal'),

)); ?>


<!-- close button ends-->

</div>

<?php $this->endWidget(); ?>

<!-- View Popup ends -->



It might save you some time or headache.

hi, how to fix in bootstrap-responsive.css this:




<div class="nav-collapse in collapse" id="collapse_0" style="height: 136px;">



in this way the dropdown not show, while if I set style=“height: auto;” all it’s ok. thanks.