Yii Framework Forum: [EXTENSION] Bootstrap - Yii Framework Forum

Jump to content

  • (45 Pages)
  • +
  • « First
  • 40
  • 41
  • 42
  • 43
  • 44
  • Last »
  • You cannot start a new topic
  • You cannot reply to this topic

[EXTENSION] Bootstrap Bringing together Yii and Twitter Bootstrap Rate Topic: ***** 23 Votes

#821 User is offline   avraham 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 08-November 12

Posted 30 December 2012 - 08:26 PM

View PostDamange, on 16 November 2012 - 06:25 AM, said:

Thanks for great extension.

I have a problem.

Bootstrap extension works fine.
When i use TbNavbar or TbMenu they don't assign active=true for current elements.


I have local server, Yii project in subfolder: base url: http : // yii.test/blog
In controller:
$this->menu = array(
	array('label'=>'Home', 'url'=>'#'),
	array('label'=>'Test', 'url'=> $this->createUrl('/test')),
	array('label'=>'Menu', 'url'=> $this->createUrl('/menu')),
	array('label'=>'User', 'url'=> $this->createUrl('/user')),
	array('label'=>'Access', 'url'=> $this->createUrl('/rights')),
);


In View:
<?php $this->widget('bootstrap.widgets.TbNavbar', array(
  'type'=>'inverse',
  'brand'=>Yii::app()->name,
  'brandUrl'=>'#',
  'collapse'=>true,
  'items'=>array(
	  array(
		  'class'=>'bootstrap.widgets.TbMenu',
		  'items'=>$this->menu,
	  ),
  ),
)); ?>



Widget generate nice menu. All links works. Application contains test, menu, user and right Controller. But cueent item don't hihglight.

Where my mistake?


===========================
I change url'=>$this->createUrl('/test') for 'url'=>array('/test'). New code generates same links.


I play with parameters and create new menu:
$this->menu = array(
	array('label'=>'Home', 'url'=>'#'),
	array('label'=>'Test', 'url'=> array('/test/default/index')),
	array('label'=>'Menu', 'url'=> array('/menu/default/index')),
	array('label'=>'User', 'url'=> array('/user/default/index')),
	array('label'=>'Access', 'url'=> array('/rights/default/index')),
);


If I put full path: /module/controller/method - active style works fine.
But I want see active TEST menu element for all links /test/*.
How do this?


Did you solve your problem, I'm having the same issue, my bootstrap.widgets.TbMenu widget is not setting the active property.
0

#822 User is offline   pod2g 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 17
  • Joined: 20-May 12

Posted 10 January 2013 - 09:06 PM

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:

Quote

"if a remote url is provided, content will be loaded via jQuery's load method and injected into the .modal-body. If you're using the data api, you may alternatively use the href tag to specify the remote source. An example of this is shown below:
<a data-toggle="modal" href="remote.html" data-target="#modal">click me</a>".



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
0

#823 User is offline   Sage 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 14
  • Joined: 29-August 12
  • Location:California, USA

Posted 15 January 2013 - 04:37 PM

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.
0

#824 User is offline   realtebo 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 535
  • Joined: 03-October 12
  • Location:Ferrara

Posted 17 January 2013 - 03:23 AM

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 ?!
Il computer non ragiona, ma ha sempre ragione.
Ricordalo quando fai il debug
0

#825 User is offline   Don Felipe 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 113
  • Joined: 02-January 11
  • Location:Saigon, Vietnam

Posted 17 January 2013 - 03:56 AM

View PostSage, on 15 January 2013 - 04:37 PM, said:

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 doesn't [work]:
<?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.


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

Cheers, Felipe
0

#826 User is offline   Don Felipe 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 113
  • Joined: 02-January 11
  • Location:Saigon, Vietnam

Posted 17 January 2013 - 05:03 AM

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".
0

#827 User is offline   compugator 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 43
  • Joined: 01-May 11

Posted 18 January 2013 - 11:51 PM

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

<?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'=>'#'),
                )),
            ),
        ),
    ),
)); ?>

into my homepage and the dropdowns won't work.

Confused.
0

#828 User is offline   gwx 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 18-January 13

Posted 20 January 2013 - 03:46 PM

how can i use it with giix? thanks
0

#829 User is offline   renathy 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 82
  • Joined: 05-July 11

Posted 20 January 2013 - 05:31 PM

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?
0

#830 User is offline   vildenxx 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 12-December 12

Posted 22 January 2013 - 05:49 AM

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.
0

#831 User is offline   yiicoding 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 21-January 13

Posted 23 January 2013 - 06:43 AM

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?
0

#832 User is offline   realtebo 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 535
  • Joined: 03-October 12
  • Location:Ferrara

Posted 24 January 2013 - 04:30 AM

Is there a way to user an other gridview into a relational table row ?
Il computer non ragiona, ma ha sempre ragione.
Ricordalo quando fai il debug
0

#833 User is offline   Aurum 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 24-December 11

Posted 24 January 2013 - 08:15 AM

Help me please.
How to get or set value to 'bootstrap.widgets.TbButtonGroup' radio or checkbox
like a CHtml::checkBox
0

#834 User is offline   leibra 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 28-March 12

Posted 30 January 2013 - 02:51 AM

View PostDon Felipe, on 17 January 2013 - 03:56 AM, said:

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

Cheers, Felipe


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
0

#835 User is offline   Xích Lô 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 30-January 13

Posted 30 January 2013 - 09:52 PM

Thanks all, i install success
0

#836 User is offline   swampone 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 40
  • Joined: 28-March 11

Posted 31 January 2013 - 05:23 PM

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; }
}

0

#837 User is offline   mirunho 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 170
  • Joined: 19-December 12
  • Location:Gdansk, Poland

Posted 01 February 2013 - 02:40 AM

View Postrenathy, on 20 January 2013 - 05:31 PM, said:

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?


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.
0

#838 User is offline   mirunho 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 170
  • Joined: 19-December 12
  • Location:Gdansk, Poland

Posted 01 February 2013 - 06:13 AM

View PostJames Landau, on 13 November 2012 - 03:43 AM, said:

Hey there --

I love this extension and its functionalities, though I'm hitting a wall with TbGridView. Maybe this is something people have already discovered/worked through, but I'm having trouble with the filtering function.

Some context: I have a referral model with the following (standard, Gii-created) search() function.

public function search()
	{

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('referName',$this->referName,true);
		$criteria->compare('route',$this->route,true);
		$criteria->compare('publisher',$this->publisher,true);
		$criteria->compare('channel',$this->channel,true);
		$criteria->compare('active',$this->active,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));


In my ReferralController.php, I have the following index() function, which creates the data provider from the Referral model. It also passes a referral param for potential filtering.
public function actionIndex()
	{

		$dataProvider=new CActiveDataProvider('Referral');

		$this->render('index',array(
			'dataProvider'=>$dataProvider,
			'referral'=> New referral(),
		));
	}


The following code will generate a nice, pretty gridview with search fields... that don't work.

<?php $this->widget('bootstrap.widgets.TbGridView', array(
    'type'=>'striped bordered condensed',
    'dataProvider'=>$dataProvider,
    'template'=>"{items}",
    'filter'=>$referral,
    'columns'=>array(
        array('name'=>'id', 'header'=>'#'),
        array('name'=>'referName', 'header'=>'Referral Name'),
        array('name'=>'route', 'header'=>'Redirect To'),
        array('name'=>'publisher', 'header'=>'Publisher'),
        array('name'=>'channel', 'header'=>'Channel'),
        array('name'=>'active', 'header'=>'Active'),
        array(
            'class'=>'bootstrap.widgets.TbButtonColumn',
            'htmlOptions'=>array('style'=>'width: 50px'),
        ),
    ),
)); ?>


If I change 'filter'=>$referral to 'filter'=>$referral->search() as most the examples suggest, I get the following error:

CActiveDataProvider and its behaviors do not have a method or closure named "getValidators".

I've attached a copy of the stack trace if anyone has any ideas. I have a feeling this is an obvious mistake, but I'm just not seeing it.

Any help would be greatly appreciated--


Did You find any solution, or someone else did ?
0

#839 User is offline   grmpz 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 12
  • Joined: 21-August 12

Posted 01 February 2013 - 04:11 PM

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.
0

#840 User is offline   grmpz 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 12
  • Joined: 21-August 12

Posted 01 February 2013 - 04:41 PM

View Postyiicoding, on 23 January 2013 - 06:43 AM, said:

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?


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.
0

Share this topic:


  • (45 Pages)
  • +
  • « First
  • 40
  • 41
  • 42
  • 43
  • 44
  • Last »
  • You cannot start a new topic
  • You cannot reply to this topic

2 User(s) are reading this topic
0 members, 2 guests, 0 anonymous users