How to link to new blank page in tbbuttongroup yii - yii

Given tbbuttongroup when user clicks the items I want to open a link to new blank page. I've tried the code below but it doesn't work.
<?php
$this->widget(
'bootstrap.widgets.TbButtonGroup',
array(
'type' => 'primary',
// '', 'primary', 'info', 'success', 'warning', 'danger' or 'inverse'
'buttons' => array(
array('label' => 'Action', 'url' => '#'),
array(
'items' => array(
array(
'label' => 'Cetak ke Pdf',
'url' => array("Tbpinjaman/cetakpdf",id=>$_GET[id]),
'target'=>'_blank',
),
array('label' => 'Export ke Excel', 'url' => 'Tbpinjaman/admin'),
)
),
),
)
);

<?php
$this->widget(
'bootstrap.widgets.TbButton', array(
'url'=> 'http://stackoverflow.com/',
'label'=>Yii::t('strings', 'stackoverflow'),
'htmlOptions' => array('target'=>'_blank')
));
?>
target on button widget must be put on htmloptions :
'htmlOptions' => array('target'=>'_blank')

Use linkOptions for your anchor items
'linkOptions' => array
(
'onclick' => "javascript:window.open('Tbpinjaman/cetakpdf/$_GET[id]','Your window name','width=500,height=700'); return false;"
)
Your code will come like this.
<?php
$this->widget('bootstrap.widgets.TbButtonGroup', array
(
'type' => 'primary',
'buttons' => array
(
array('label' => 'Action', 'url' => '#', 'htmlOptions' => array('id' => 'buttonStateful'),),
array
(
'items' => array
(
array
(
'label' => 'Cetak ke Pdf',
'url' => '#',
'linkOptions' => array
(
'onclick' => "javascript:window.open('Tbpinjaman/cetakpdf/$_GET[id]','Your window name','width=500,height=700'); return false;"
)
),
array
(
'label' => 'Export ke Excel',
'url' => '#',
'linkOptions' => array
(
'onclick' => "javascript:window.open('Tbpinjaman/admin','Your window name','width=500,height=700'); return false;"
)
)
)
)
)
));
?>

Try this :
<?php
$this->widget(
'bootstrap.widgets.TbButtonGroup',
array(
'type' => 'primary',
// '', 'primary', 'info', 'success', 'warning', 'danger' or 'inverse'
'buttons' => array(
array('label' => 'Action', 'url' => '#'),
array(
'items' => array(
array(
'label' => 'Cetak ke Pdf',
'url' => array("Tbpinjaman/cetakpdf",id=>$_GET[id]),
**'htmlOptions' => array('target'=>'_blank'),**
),
array('label' => 'Export ke Excel', 'url' => 'Tbpinjaman/admin'),
)
),
),
)
);

Related

Cannot do filtering via a dropdown menu in Yii TbGridView (v1.x.x)

I am trying to get the filtering to run although I am having some issues below is my view note that this in in a PARTIAL view :-
If I click on the header of the column it does the sorting as expected, however if I select an option from the dropdown it doesn't filter the items...
Any ideas?
<?php
$myuser = new Myuser('search');
$filterBtn = $this->widget('bootstrap.widgets.TbButton', array(
'icon' => 'filter',
'size' => 'small',
'label' => $myuser->paging ? 'View All' : 'View Less',
'htmlOptions' => array('class'=>'pull-right', 'style'=> 'margin:20px 0;'),
'url' => $myuser->paging ? array('/carrot/myuser/admin/paging/0') : array('/carrot/myuser/admin')
), true);
$this->widget('bootstrap.widgets.TbGridView',array(
'id' => 'myuser-grid','type'=>'striped bordered condensed',
'dataProvider' => $myuser->search(),
'filter' => $myuser,
'columns' => array(
array(
'id' => 'user_id',
'class' => 'CCheckBoxColumn',
'checked' => 'in_array($data->user_id, $this->grid->owner->model->student_ids)',
'checkBoxHtmlOptions' => array(
'name' => 'selected_student_id[]',
)
),
'firstname',
'surname',
'username',
array(
'name' => 'year_id',
'filter' => CHtml::activeDropDownList($myuser, 'year_id', CHtml::listData(Organisation::model()->distinctYears, 'year_id', 'year_id'), array('prompt'=>'All Years')),
'htmlOptions' => array('style' => 'text-align:center;'),
'headerHtmlOptions' => array('style' => 'text-align:left;'),
),
array(
'name' => 'form_name',
'header' => 'Form',
'filter' => CHtml::activeDropDownList($myuser, 'form_name', CHtml::listData(Organisation::model()->distinctForms, 'form_name', 'form_name'), array('prompt'=>'All Forms')),
),
array(
'name' => 'House',
'filter' => CHtml::activeDropDownList($myuser, 'House', CHtml::listData(Organisation::model()->distinctHouses, 'House', 'House'), array('prompt'=>'All Houses')),
),
),
)); ?>
My model has the following search() method:
public function search($limit = false)
{
$criteria = new CDbCriteria();
$criteria->compare('t.user_id',$this->user_id,true);
$criteria->compare('t.firstname',$this->firstname,true);
$criteria->compare('t.surname',$this->surname,true);
$criteria->compare('t.username',$this->username,true);
$criteria->compare('t.year_id',$this->year_id);
$criteria->compare('t.form_name',$this->form_name);
$criteria->compare('t.House',$this->House);
$criteria->compare('o.organisation_id',$this->organisation_id);
$criteria->group = 't.user_id';
$criteria->together = true;
return new CActiveDataProvider($this->currentUserOrganisation(), array(
'criteria' => $criteria,
'pagination' => array(
'pageSize' => $this->paging ? ($limit) ? $limit : OverviewController::PAGE_SIZE : 2000
),
'sort' => array(
'defaultOrder' => array('firstname'=>false, 'surname'=>false),
'attributes' => array(
'organisation_name' => array(
'asc' => 'organisation_name',
'desc' => 'organisation_name DESC',
'default' => 'desc',
),
'*'
)
),
));
}
I think you can't use a DropDownList as filter, but you can easily use CHTML::listData():
array(
'name' => 'year_id',
'filter' => CHtml::listData(Organisation::model()->distinctYears, 'year_id', 'year_id'),
'htmlOptions' => array('style' => 'text-align:center;'),
'headerHtmlOptions' => array('style' => 'text-align:left;'),
),
array(
'name' => 'form_name',
'header' => 'Form',
'filter' => CHtml::listData(Organisation::model()->distinctForms, 'form_name', 'form_name'),
),
array(
'name' => 'House',
'filter' => CHtml::listData(Organisation::model()->distinctHouses, 'House', 'House'),
),
This will automatically generate a DropDownList for you.
I hope this works for you.

bulkactions with dropdown list yii booster

Is there a way to have a dropdown option rather than a link or button or... buttongroup as the buttonType?
$this->widget ( 'bootstrap.widgets.TbExtendedGridView', array (
'id'=>'grid',
'dataProvider'=>$dataProvider,
'bulkActions' => array(
'actionButtons' => array(
array(
'buttonType' => 'select',//?
'type' => 'primary',
'size' => 'small',
'label' => 'Batch',
'url' => array('batchUpdate'),
'id' => 'child_id',
'click' => ''
)
),....

bootstrap.widgets.TbDetailView, Yii app

Model--
enter code here
public function searchShop()
{
$criteria = new CDbCriteria();
$criteria->compare("name", $this->category, TRUE, "OR");
$criteria->compare("shopname", $this->category, TRUE, "OR");
$criteria->compare("category", $this->category, TRUE, "OR");
return Shops::model()->findAll($criteria);
}
code----
enter code here
<?php
foreach($models as $model):
$this->widget(
'bootstrap.widgets.TbDetailView',
array(
'type'=>'bordered condensed',
'data' => array(
'id' =>array('view', 'id'=>$model->ID),
'Shop Name' => $model->shopname,
'Category' => $model->category,
'ID' => CHtml::link(CHtml::encode($model->ID), array('view', 'id'=>$model->ID))
),
'attributes' => array(
array('name' => 'Shop Name', 'label' => 'Shop name'),
array('name' => 'Category', 'label' => 'Category'),
array('name' => 'ID', 'label' => 'ID'),
),
)
);
echo "<br><hr><br>";
endforeach;
?>
I want a link on ID by clicking on it it will render view file i.e view.php of shops model
I used CHtml::link(CHtml::encode($model->ID), array('view', 'id'=>$model->ID)) but it is showing path of that view as 1
help me...
thanks in advance
try
CHtml::link(CHtml::encode($model->ID),
CController::createUrl('site/view',array('id'=>$model->ID)))
here i have assumed that action view lies in site controller. If it lies under some other module name then you can write like this "moduleName/controllerName/actionName"
Edit:
Ok you have to try a few things. TbDetailView extends CDetatilView. Now you can use TbDetailView as
$this->widget(
'bootstrap.widgets.TbDetailView',
array(
'type'=>'bordered condensed',
'data' => array(
'id' =>array('view', 'id'=>$model->ID),
'Shop Name' => $model->shopname,
'Category' => $model->category,
),
'attributes' => array(
array('name' => 'Shop Name', 'label' => 'Shop name'),
array('name' => 'Category', 'label' => 'Category'),
array('label' => 'ID', 'value' => CHtml::link(CHtml::encode($model->ID), array('view', 'id'=>$model->ID))),
),
)
);
You can also do like
$this->widget(
'bootstrap.widgets.TbDetailView',
array(
'type'=>'bordered condensed',
'data' =>$model,
'attributes' => array(
array('name' => 'shopname', 'label' => 'Shop name'),
array('name' => 'category', 'label' => 'Category'),
array('value' => CHtml::link(CHtml::encode($model->ID), array('view', 'id'=>$model->ID))
),, 'label' => 'ID'),
),
)
)
;

YiiBooster Navbar target _blank

I am using the navbar of the extension Yiibooster, but I am having problems with a subitem of the menu, I need to go to a new tab, but I can't make it.
<?php $this->widget(
'bootstrap.widgets.TbNavbar',
array(
'brand' => '<img src ="' . Yii::app()->request->baseUrl . '/images/FAVICON.png" />Inicio',
'fixed' => false,
'collapse' => true,
'items' => array(
array(
'class' => 'bootstrap.widgets.TbMenu',
'items' => array(
array(
'label' => 'Informes',
'items' => array(
array('label' => 'Listado de Activos', 'url' => Yii::app()->baseUrl.'/ZfInmuebles/verpdf',
'itemOptions' => array('target' => '_blank')),
)),
If you want go to blank only in one item of the menu, this is the best option:
'items' => array(
array(
'label' => 'Informes',
'items' => array(
array(
'label' => 'Listado de Activos',
'url' => Yii::app()->baseUrl.'/ZfInmuebles/verpdf',
'linkOptions' => array(
'target' => '_blank'
),
),
),
),
)
Yii CMenu docs: http://www.yiiframework.com/doc/api/1.1/CMenu#items-detail
add class=>'bootstrap.widgets.TbMenu' like
'items' => array(
array(
'class' => 'bootstrap.widgets.TbMenu',
'submenuOptions' => array('target' => '_blank'),
'items' => array(
array('label' => 'Listado de Activos',
'url' => Yii::app()->baseUrl.'/ZfInmuebles/verpdf',
),
)
)
You need to use $brandOptions:
NavBar::begin([
'brandLabel' => 'Label text',
'brandUrl' => '/'.Yii::$app->homeUrl,
'brandOptions' => [
'target'=>'_blank'
],
'options' => [
'class' => 'navbar-inverse navbar-fixed-top',
],
]);

Yiibooster modal from navbar

I need to call my modal widget from a navbar using Yiibooster
<?php $this->widget(
'bootstrap.widgets.TbNavbar',
array(
'brand' => 'Inicio',
'fixed' => false,
'items' => array(
array(
'class' => 'bootstrap.widgets.TbMenu',
'items' => array(
array('label' => 'Home', 'url' => '#', 'active' => true),
array('label' => 'Filtro', 'htmlOptions' => array('data-toggle' => 'modal','data-target' => '#myModal'),
array('label' => 'Nuevo', 'url' => Yii::app()->baseUrl.'/ZfInmuebles/create'),
)
)
)
)
));?>
htmlOptions doesnt work there, what can i do?
Use linkOptions instead of htmlOptions
...
array('label' => 'Filtro', 'linkOptions' => array('data-toggle' => 'modal','data-target' => '#myModal')),
...
<?php $this->widget(
'bootstrap.widgets.TbNavbar',
array(
'brand' => 'Zona Franca',
'fixed' => false,
'collapse' => true,
'items' => array(
array(
'class' => 'bootstrap.widgets.TbMenu',
'items' => array(
array('label' => 'Inicio', 'url' => Yii::app()->baseUrl),
array('label' => 'Nuevo', 'url' => Yii::app()->baseUrl.'/ZfArrendatarios/create'),
)),
array(
'class' => 'bootstrap.widgets.TbMenu',
'htmlOptions' => array('data-toggle' => 'modal','data-target' => '#myModal'),
'items' => array(
array('label' => 'Filtro', 'url' => '#myModal'),
)),
)
)
)
;?>
There you have the answer :D