[EXTENSION] Bootstrap

That’s a good one, cappadochian, but it never pass the first if statement (the $_POST). I’m lost with this.

That’s weird. I think it’s because your form is not connected to your model properly.

What do you have in your controller?




    public function actionUpdateOwn(){

        $user = substr(Yii::app()->request->getQueryString(),20); // I'll change this later

        if($user == Yii::app()->user->id){

            $model=$this->loadModel($user);

            if(isset($_POST['updateEmailForm'])){ // Never passes from here

                $model->setAttributes($_POST['updateEmailForm']);

                if($model->save()){

                    if(Yii::app()->getRequest()->getIsAjaxRequest())

                        Yii::app()->end();

                    else

                        $this->redirect(array('updateOwn'));

                }

            }

            $this->render('updateOwn',array(

                'model'=>$model,

            ));

        }

        else

            throw new CHttpException(403,'No puede modificar el perfil de otro usuario.');

    }






    public function actionUpdateEmail(){

        $model=$this->loadModel(Yii::app()->user->id);

        $this->performAjaxValidation($model);

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

        {

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

            $user = User::model()->findByPk($model->id);

            $model->userName = $user->userName;

            $model->passwordNew = '';

            $model->passwordNewRepeat = '';

            if(md5($model->password) == $user->password)

                if($model->save())

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

            else

                echo '<br/><br/><h4>Clave incorrecta</h4>';

        }


        $this->render('updateOwn',array(

            'model'=>$model,

        ));

    }



Since it never pass that if statement, never enters to the actionUpdateEmail function.

I think the solution must be very simple, but I’m very new at Yii.

Thanks in advance.

I think this is the wrong part:




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



you have to put the same name as the model. If you have a model named User, you have to handle it like this




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



check the name of the post variable with firebug.

Hi, sometimes I need to choose if I want to show or not a TbButtonGroup. I mean not ButtonGroup items, just ButtonGroup. To do it’s very simple, just add two lines of code in TbButtonGroup.php :

After public $dropup = false add these lines




/**

* @var boolean indicates whether if ButtonGroup shold be visible. Defaults to 'true'

**/

public $visible = true;



then, in run() method add:




public function run()

{

   if($this->visible === false) return;


[...]



Cappadochian, thanks for your help but I cannot solve my problem. If I change ‘updateEmailForm’ to ‘User’, it enters to the if statement but now:

How can I get the modified fields from updateEmailForm? In fact it never calls actionUpdateEmail().

I see that you don’t understand even the basics (however I’m also by far not an expert yet, but at least I understand the basics). I strongly recommend you to at first watch some youtube videos about OOP and MVC architecture regarding PHP.

For now, the point is, that if you see the form, it means you are inside the actionUpdateEmail() function.

If you hit the submit button, you enter the following IF statement:




if(isset($_POST['User'])) {...



because you are posting attributes (the filled form fields’ values) for the model User.

and this is the part, where you make the model’s attributes’ values equal to the values you have entered in the form:




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



this is called massive assignment, you have to read about it.

professionals, please correct me if I’m wrong.

Can i know how to get popbox to login for my application. i’m also using bootstrap extension. here is my main.php file of layout.

<$this->widget(‘bootstrap.widgets.TbNavbar’, array(

‘brand’=>’<img src="../images/personalTrainer.png"/>’,

‘brandUrl’ => bu(),

‘collapse’ => true,

‘items’=>array(

array(

‘class’=>‘bootstrap.widgets.TbMenu’,

‘items’=>array(

array(‘label’ => ‘Home’, ‘url’ => array(’/site/index’)),

array(‘label’ => ‘Login’, ‘url’ => array(’/user/create’), ‘visible’ => app()->user->isGuest),

array(‘label’=>’(’.Yii::app()->user->name.’)’, ‘url’=>array(’/site/logout’), ‘visible’=>!Yii::app()->user->isGuest),

),

),

),

));

?>

>

Maybe my english betrayed me. If I show you my code, you be able to see that I’ve done everything you said and that I was right about that action in the controler. Anyway… I’ve solved my problem inside actionUpdateOwn and I’ve deleted the other two actions. Thanks.

Chris83,

Just wanted to say thanks for this extension. It’s brilliant! ;D

Hi,

I have a rendering problem when I use a prepend or append icon in fields with the Popover together.

The data-content is not rendered at all (title is ok) in the popover.

Is it a known bug?

Many thanks

PS : it seems to be the 5776 issue. But in this version (2.3.2) it occurs…

Hi,

Following this topic, I tried to bring together a dropdown and a Modal.

I use the modal to add a row and to refresh the dropdown with the added value.

I wanted to use TbModal instead of CJuiDialog.

I succeeded in make it working but it appears that the main form (not in modal) is broken (CSS) and other modals too (they don’t show at all).

I think it is the div where the dialog is inserted after the click on the ajaxButton which breaks CSS.

Has someone implemented something like this?

The code likes this :

The button to launch the modal :





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

		'buttonType'=>'ajaxButton',

		'label'=>'Créer une campagne de Prospection',

		'type'=>'primary', 

		//'size'=>'small', 

		'icon'=>'plus white',

		'url'=>$this->createUrl('prospection/createdialog'),

		'ajaxOptions'=>array(

			'type'=>'POST',

			'onclick'=>' return false;',

			'update'=>'#prospection_dialog'

		),

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

)); 


		?>

		

<div id="prospection_dialog"></div>

			

<?php echo $form->dropDownListRow($model->PROSPECT,'PRCODE',CHtml::listData(PROSPECTION::model()->findAll(), 'PRCODE','PRLIBELLE'),array('data-html'=>true,'empty'=>'==Aucune==','rel'=>'twipsy','data-content'=>Yii::t('CLIENT','PROSPECT_comment')));?>



The Controller Code :


 

	public function actionCreateDialog()

	{

		Yii::log("== PROSPECTION == Create Dialog == Entrée",'info');

	

		$model = new PROSPECTION();

		

		$this->performAjaxValidation($model);

		

		$flag=true;

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

		{

			$flag=false;

	

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

			 

			if($model->save())

			{

				Yii::log('==SAVE OK==','info');

				echo CHtml::tag('option',array (

                                'value'=>$model->PRCODE,

                                'selected'=>true

                            ),CHtml::encode($model->PRLIBELLE),true);

				 

				 

				

			}		

		}

		

		if($flag) {

			Yii::app()->clientScript->scriptMap['jquery.js'] = false;

			$this->renderPartial('createDialog',array('model'=>$model,),false,true);

		}

	}



The create view :




$this->beginWidget('bootstrap.widgets.TbModal', array('id'=>'prospection_dialog_t','autoOpen'=>true)); ?>

 

<div class="modal-header">

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

    <h4>Modal header</h4>

</div>


<div class="modal-body">

    <p><?php $this->renderPartial('_formDialog',array('model'=>$model),false,true);?></p>

</div>


<div class="modal-footer">


   

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

        'label'=>'Close',

        'url'=>'#',

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

    )); ?>

</div>


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



And the form :




<?php


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

		

		'id'=>'prospection-form',

		'enableAjaxValidation'=>true,

		'type'=>'horizontal',

		//'stacked'=>false,

		'focus'=>array($model,'PRLIBELLE'),

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

)

		

		);

?>

<?php echo $form->textFieldRow($model,'PRLIBELLE',array(

		'prepend'=>'<i class="icon-align-justify"></i>',

		'data-content'=>'test',

		'rel'=>'twipsy',

		

));?>


<?php echo $form->datePickerRow($model,'PRDATE',array(

			'options'=>array(

					'format'=>'dd/mm/yyyy',

				),

			'prepend'=>'<i class="icon-calendar"></i>',

		

		

));?>


<div class="form-actions">

<?php 

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

			'buttonType'=>'ajaxSubmit',

			'label'=>'Créer',

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

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

			'icon'=>'plus white',

			'url'=>CHtml::normalizeUrl(array('prospection/createdialog','render'=>false)),

			'ajaxOptions'=>array('success'=>'js: function(data) {

                        $("#PROSPECT_PRCODE").append(data);

						 $("#prospection_dialog").dialog("close");

                    }'),

	 		'htmlOptions'=>array('id'=>'closeProspectionDialog','class'=>'pull-right','data-dismiss'=>'modal',),

	)); ?>

</div>

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




Hi,

I have created a column for GridView with a TbButton that make an Ajax call and perform a ‘Flag-like’ operation.

The button is working properly but in case of GridView update (through Javascript yiiGridView.update()), the renderDataCellContent which contains the TbButton widget does not include the javascript linked to the button click…

So, after the new row addition with the Gridview update that contains my button, the button link does not work.

Do you have a workaround for that ?

Many thanks

Hi Yii!! i want to show a TbModal in a TbListView to post the selected project details.

This is what i tried:

I have Projects model, with:

ProjectsController.php actionProjectList()





public function actionProjectList() <= This action show a list of projects

	{

		$model=new Projects('search');

		$model->unsetAttributes();  // clear any default values

		if(isset($_GET['Projects']))

			$model->attributes=$_GET['Projects'];

                $this->render('projects',array(

			'dataProvider'=>$model->search(),

                        'model'=>$model,

		));

	}




public function actionProjectDetail($id) <= This action show project details

	{

            $data=$this->loadModel($id);

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

            {

                echo CJSON::encode(array(

                    'div'=>$this->renderPartial('_projectDetail',

                        array('data'=>$data,),

                        true

                    )

                ));

            }

            else

                $this->render('projectDetail',array('data'=>$data,));

            



The projects.php view





<div id="projectList">

    <?php 

        $this->beginWidget('bootstrap.widgets.TbModal', array('id' => 'projectDetail'),false);  <= TbModal for project details ###

        echo '<div class="modal-header">

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

            </div>';

        echo '<div class="modal-body">';

        echo '<div class="divForProjectDetail"></div>';  <= div for project details ###

        echo '</div>';

    $this->endWidget();

        

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

            'dataProvider'=>$dataProvider,

            'itemView'=>'_list',

            'id'=>'projectslist',

        ));

        echo '<script type="text/javascript">

        function projectDet(pid){ <= project id to show in the details TbModal  ###

        ';

        echo CHtml::ajax(array(

                    'url'=>'projectDetail/id/'.'js:pid', <= project id i got in projectDet(pid) ###

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

                    'type'=>'post',

                    'dataType'=>'json',

                    'success'=>"function(data)

                    {

                        $('#projectDetail div.divForProjectDetail').html(data.div);

                    } ",

                    ));

        echo 'return false;

        }

        </script>';

        ?>

    </div>



_list.php

[size="2"]





<div class="project-item">

                        <h5><b><?php echo CHtml::link(CHtml::encode($data->title), array('//projects/projects/projectDetail', 'id' => $data->id), array('data-toggle'=>'modal', 'data-target'=>'#projectDetail', 'onclick'=>'{projectDet('.$data->id.');}')); ?></b></h5>

</div>



[/size]

projectDetail.php




<?php echo $this->renderPartial('_projectDetail', array('data'=>$data)); ?>



_projectDetail.php




<div class="project-detail">

                        <h5><b><?php echo CHtml::encode($data->title); ?></b></h5>

                        <?php echo CHtml::encode($data->projectUser->username); ?>

       				<?php echo date('j M / y ',strtotime($data->date)); ?>

       				<?php echo CHtml::encode($data->rate); ?>

</div>



[size=“2”]So, the problem is the ‘url’ parameter in CHtml::ajax, i tried with:[/size]





<div id="projectList">

......

        echo '<script type="text/javascript">

        function projectDet(pid){

        ';

        echo CHtml::ajax(array(

                    'url'=>'projectDetail/id/4', <-- Fixed Value##############

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

                    'type'=>'post',

                    'dataType'=>'json',

                    'success'=>"function(data)

                    {

                        $('#projectDetail div.divForProjectDetail').html(data.div);

                    } ",

                    ));

        echo 'return false;

        }

        </script>';

        ?>

    </div>



and it works, when i click on a project the TbModal shows the project with ‘id’=4

How can i use the ‘pid’ parameter of the projectDet(pid) function in the ‘url’ CHtml::ajax parameter?

Thanks Yii!

After inserting the following line to my config file (server.development.php)


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

I get this:

I tried it without creating an Alias and using ‘class’=>‘ext.bootstrap.components.Bootstrap’, instead, but also failed:

What am I doing wrong?

Did you solve this? I have the same issues. Any help would be appreciated!

Hi Everyone,

Anyone tried to use "inlineErrors" attribute in " bootstrap.widgets.TbActiveForm" .

Since i am trying to set this attribute in form but its not working.Anyone can confirm it.Is it bug or something else.

This is my code.




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

    'id'=>'employee-form',

    'type'=>'horizontal',

   'enableAjaxValidation'=>false,

   'inlineErrors'=>false

)); 



Thanks in Advance.

[color="#333333"][font="Arial, sans-serif"][size="4"]I have followed below instructions to set main.config (the same instruction mentioned in http://cniska.net/yii-bootstrap/setup.html)[/size][/font][/color]

[color="#333333"][font=“Arial, sans-serif”][size=“4”]// Define a path alias for the Bootstrap extension as it’s used internally. // In this example we assume that you unzipped the extension under protected/extensions. Yii::setPathOfAlias(‘bootstrap’, dirname(FILE).’/../extensions/bootstrap’);[/size][/font][/color]

[color="#333333"][font=“Arial, sans-serif”][size=“4”]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’, ), ), );[/size][/font][/color]

[color="#333333"][font="Arial, sans-serif"][size="4"]but when i try to open gii I get the following error:[/size][/font][/color]

[color="#333333"][font="Arial, sans-serif"][size="4"]Alias "gii.GiiModule" is invalid. Make sure it points to an existing PHP file and the file is readable.[/size][/font][/color]

[color="#333333"][font="Arial, sans-serif"][size="4"]I noticed that the provided configuration instruction do not contain the following text in gii module array in the main.config file[/size][/font][/color]

[color="#333333"][font="Arial, sans-serif"] [/font][/color]


[color="#333333"][font="Arial, sans-serif"][size="4"]'modules' => array([/size][/font][/color]

[color="#333333"][font="Arial, sans-serif"][size="4"]        'gii' => array([/size][/font][/color]

[color="#333333"][font="Arial, sans-serif"][size="4"]**            'class' => 'system.gii.GiiModule',[/size][/font][/color]

[color="#333333"][font="Arial, sans-serif"][size="4"]            'password' => 'gii',**[/size][/font][/color]

[color="#333333"][font="Arial, sans-serif"][size="4"]        )[/size][/font][/color]

[color="#333333"][font="Arial, sans-serif"][size="4"]    )[/size][/font][/color]



[color=#333333][font=Arial, sans-serif][size=2]which caused the problem of error above. so I updated my main.config to be like below:[/size][/font][/color]

[color="#333333"][font="Arial, sans-serif"] [/font][/color]




[color="#333333"][font="Arial, sans-serif"][size="4"]    'modules' => array([/size][/font][/color]

[color="#333333"][font="Arial, sans-serif"][size="4"]        'gii' => array([/size][/font][/color]

[color="#333333"][font="Arial, sans-serif"][size="4"]            'class' => 'system.gii.GiiModule',[/size][/font][/color]

[color="#333333"][font="Arial, sans-serif"][size="4"]            'password' => 'gii',[/size][/font][/color]

[color="#333333"][font="Arial, sans-serif"][size="4"]            // If removed, Gii defaults to localhost only. Edit carefully to taste.[/size][/font][/color]

[color="#333333"][font="Arial, sans-serif"][size="4"]            'ipFilters' => array('127.0.0.1', '::1'),[/size][/font][/color]

[color="#333333"][font="Arial, sans-serif"][size="4"]            'generatorPaths' => array([/size][/font][/color]

[color="#333333"][font="Arial, sans-serif"][size="4"]                'bootstrap.gii',),[/size][/font][/color]

[color="#333333"][font="Arial, sans-serif"][size="4"]        ),[/size][/font][/color]



[color="#333333"][font="Arial, sans-serif"] [/font][/color]

[color="#333333"][font="Arial, sans-serif"][size="4"]the gii module worked fine and i can generate models,views,controller as usual.[/size][/font][/color]

[color="#333333"][font="Arial, sans-serif"][size="4"]But they are not generated with bootstrap widgets. so how can I use yii-bootstrap and gii to generate views with bootstrap widgets ?[/size][/font][/color]

[color="#333333"][font="Arial, sans-serif"][size="4"]Thanks in advanced.[/size][/font][/color]

Did someone already work on a migration of this extension to Bootstrap 3?

I know that the official RC hasn’t been released yet, but I still already want to upgrade to Bootstrap 3, since the new mobile first features seem very attractive.

Chuntley, thanks for your answer, help me a lot.