Yii 1.1.21 : is it possible to create two dropdown buttons in the same button group? - yii

I am new to Yii, and I have been LOOKING for documentation on Yii and CMenu. I have used Phalcon and various other frameworks with similar options, but Yii's menu engine is new to me.
I am trying to create a button menu with two drop down menu buttons, each with sub menu items, like this:
Drop Down Button Group
But what is being rendered by the Yii CMenu engine is two drop down menus overlayed on each other and both are being triggered by the same buttons. Like this:
enter image description here
Looking at the rendered code, it looks like the two dropdown menus are being assigned the "dropdown-menu" class by CMenu, (or whatever the bootstrap enabled lib is) and becasue they are in the same button group, when the "open" class is assigned, it's opening BOTH dropdowns at the same time.
So my question is simple, is is even possible, using the CMenu menu arrays, to have two dropdowns in the same. Is there a menu "Item Option" or "HTML Option" I can add to the menu item properties that will all this to reference two different css tags? I know I gotta be missing something.
Here is how the menu's are being built in the view.
$this->menu = array_merge($this->menu, array(
array(
'label' => '<span class="hidden-xs hidden-sm">' . Yii::t('app', 'Export') . '</span>',
'encodeLabel' => false,
'htmlOptions' => array('id' => 'export-or-email-btn', 'class' => 'navbar-btn btn-sm',),
'items' => array(
array(
'label' => Yii::t('app', 'Export'),
'icon' => 'fa fa-file-excel-o',
'visible' => true,
'itemOptions' => array('class' => 'work-order-export-btn'),
),
array(
'label' => Yii::t('app', 'Email Export'),
'icon' => 'fa fa-envelope-o',
'visible' => true,
'itemOptions' => array('id' => $model->getClassName(), 'class' => 'email-export-btn', 'data-grid-id' => 'work-order-grid'),
),
array(
'label' => Yii::t('app', 'Export as Import Template'),
'icon' => 'fa fa-file-excel-o fa-lg',
'visible' => true,
'itemOptions' => array('class' => 'work-order-export-import-btn'),
),),),);
$this->menu = array_merge($this->menu, array(
array(
'label' => '<span class="hidden-xs hidden-sm">' . Yii::t('app', 'Actions') . '</span>',
'encodeLabel' => false,
'htmlOptions' => array(
'id' => 'work-order-actions-btn work-order-actions',
'class' => 'navbar-btn btn-sm',
'style' => 'margin: 0 0 0 15px;',
),
'items' => array(
array(
'icon' => 'fa fa-print fa-lg',
'label' => Yii::t('app', 'Print to PDF'),
'visible' => true,
'itemOptions' => array(
'class' => 'work-order-print-pdf',
),),
array(
'icon' => 'fa fa-print fa-lg',
'label' => Yii::t('app', 'Print'),
'visible' => true,
'itemOptions' => array(
'class' => 'work-order-print-selected',
),),))));
and here is the rendered code snippet:
<div class="btn-toolbar">
<div class="operations btn-group-sm btn-group open">
<button id="export-or-email-btn" class="navbar-btn btn-sm btn btn-primary dropdown-toggle" data-toggle="dropdown" name="yt7" type="button">
<span class="hidden-xs hidden-sm">Export</span>
<span class="caret"></span>
</button>
<ul id="yw6" class="dropdown-menu">
<li class="work-order-export-btn nav-header" data-ol-has-click-handler="">
<i class="fa fa-file-excel-o"></i> Export
</li>
<li id="WorkOrder" class="email-export-btn nav-header" data-grid-id="work-order-grid" data-ol-has-click-handler="">
<i class="fa fa-envelope-o"></i> Email Export
</li>
<li class="work-order-export-import-btn nav-header" data-ol-has-click-handler="">
<i class="fa fa-file-excel-o fa-lg"></i> Export as Import Template
</li>
</ul>
<button id="work-order-actions-btn work-order-actions" class="navbar-btn btn-sm btn btn-primary dropdown-toggle" style="margin: 0 0 0 15px;" data-toggle="dropdown" name="yt8" type="button">
<span class="hidden-xs hidden-sm">Actions</span>
<span class="caret"></span>
</button>
<ul id="yw7" class="dropdown-menu">
<li class="work-order-print-pdf nav-header">
<i class="fa fa-print fa-lg"></i> Print PDF
</li>
<li class="work-order-print-selected nav-header">
<i class="fa fa-print fa-lg"></i> Print Selected
</li>
</ul>
</div>
</div>

I think your problem is you are merging both arrays in the same $this->menu attribute.
Maybe you should use CMenu as widget like in the documentation
$this->widget('zii.widgets.CMenu', array(
'items'=>array(
// Important: you need to specify url as 'controller/action',
// not just as 'controller' even if default action is used.
array('label'=>'Home', 'url'=>array('site/index')),
// 'Products' menu item will be selected no matter which tag parameter value is since it's not specified.
array('label'=>'Products', 'url'=>array('product/index'), 'items'=>array(
array('label'=>'New Arrivals', 'url'=>array('product/new', 'tag'=>'new')),
array('label'=>'Most Popular', 'url'=>array('product/index', 'tag'=>'popular')),
)),
array('label'=>'Login', 'url'=>array('site/login'), 'visible'=>Yii::app()->user->isGuest),
),
));
For more information and attributes check out the official documentation here.

Related

Cakephp 3 paginator template with Bootsrap problem with sort()

Currently using paginator sort link inside a bootstrap list like this :
<ul id="myTab" class="nav nav-tabs nav-stacked">
<li class="list-group-item list-group-item-info">Filtrer les résultats de recherche pour les tweets.</li>
<li><?= $this->Paginator->sort('created','<span class="glyphicon glyphicon-time"></span> Les plus anciens',['escape' => false,'direction' => 'asc', 'lock' => true]);?></li>
<li><?= $this->Paginator->sort('created','<span class="glyphicon glyphicon-time"></span> Les plus récents',['escape' => false,'direction' => 'desc', 'lock' => true]);?></li>
<li><?= $this->Paginator->sort('nb_partage','<span class="glyphicon glyphicon-share"></span> Les plus partagés',['escape' => false,'direction' => 'desc', 'lock' => true]);?></li>
<li><?= $this->Paginator->sort('nb_like','<span class="glyphicon glyphicon-heart"></span> Les plus likés',['escape' => false,'direction' => 'desc', 'lock' => true]);?></li>
<li><?= $this->Paginator->sort('nb_commentaire','<span class="glyphicon glyphicon-comment"></span> Les plus commentés',['escape' => false,'direction' => 'desc', 'lock' => true]);?></li>
</ul>
I'm also using a paginator template like this
<?php
return [
'sort' => '<a class="list-group-item" href="{{url}}">{{text}}</a>',
];
?>
When I click on a link, it correctly displays the page and the clicked link changes class thanks to bootstrap,but not for the first two links that change classes both, all the other links work perfectly.
This is because they both sort on 'created'.
Is it possible to differentiate them so that when we click on the first or second, it changes the class not the other, as for other links.

CHtml submit button is not working when 'enter' key press in Yii

In my Yii web application, CHtml submit button is not working when 'enter' key press in Login form. My login form is,
<?php echo CHtml::beginForm(); ?>
<h3 class="form-title">Login to your account</h3>
<div class="alert alert-danger display-hide">
<button class="close" data-close="alert"></button>
<span> Enter any username and password. </span>
</div>
<div class="form-group">
<label class="control-label visible-ie8 visible-ie9">Username</label>
<div class="input-icon">
<i class="fa fa-user"></i>
<?php echo CHtml::activeTextField($model, 'username', array("class" => "form-control placeholder-no-fix", 'placeholder' => "Username")) ?>
</div>
</div>
<div class="form-group">
<label class="control-label visible-ie8 visible-ie9">Password</label>
<div class="input-icon">
<i class="fa fa-lock"></i>
<?php echo CHtml::activePasswordField($model, 'password', array("class" => "form-control placeholder-no-fix", 'placeholder' => "Password")) ?>
</div>
</div><br>
<div class="form-group">
<?php echo CHtml::submitButton(UserModule::t("Login "), array('class' => 'btn green pull-right')); ?>
</div>
<div class="text-danger"><?php echo CHtml::errorSummary($model); ?></div>
<?php echo CHtml::endForm(); ?><br><br><br>
<?php
$form = new CForm(array(
'elements' => array(
'username' => array(
'type' => 'text',
'maxlength' => 32,
),
'password' => array(
'type' => 'password',
'maxlength' => 32,
),
'rememberMe' => array(
'type' => 'checkbox',
)
),
'buttons' => array(
'login' => array(
'type' => 'submit',
'label' => 'Login',
),
),
), $model);
?>
In this login form using chtml submit button. I want to submit this login form by press enter key.
How to resolve this problem.
Please help me.
If you want to use onclick:
<?php echo CHtml::submitbutton(UserModule::t("Login "), array('class ' => 'btn green pull-right', 'onclick' => ' '));?>

CDetailView don't show properly Chtml::link's HTML data

i use Chtml::link in one CDetailView.
array(
'label'=>'Images',
'type'=>'html',
'value'=> CHtml::link('<i class="fa fa-tag"></i>','#',array('data-target'=>'#myModal','class'=>'tag','data-toggle'=>'modal')),
),
But html properly not generated. it only add few property like below
<a class="tag" href="#"><i class="fa fa-tag"></i></a>
How can i add all property?
array(
'label'=>'Images',
'type'=>'html',
'value'=> CHtml::link('<i class="fa fa-tag"></i>','#',array('data-target'=>'#myModal','class'=>'tag','data-toggle'=>'modal')),
),
change 'type'=>'html', to
'type'=>'raw',
After changing the code its look like below block
array (
'label' => 'Images',
'type' => 'raw',
'value' => CHtml::link('<i class="fa fa-tag"></i>','#',array('data-target'=>'#myModal','class'=>'tag','data-toggle'=>'modal')),
),

Styling button-column in Yii CGridview to wrap content with <div> tag inside <td>

Currently my buttons in table column comes like this
<td>
<a href="#"/>Edit</a>
<a href="#"/>Veiw</a>
<a href="#"/>Delete</a>
</td>
I want it to do like
<td>
<div class="wrapper">
<a href="#"/>Edit</a>
<a href="#"/>Veiw</a>
<a href="#"/>Delete</a>
</div>
</td>
Please suggest some way to configure it. Thanks
You have to customize cgidview code as below:
array(
'class' => 'YouCSSClass',
'template' => '{view} {update} {delete}',
),
Modify the column template of your Grid
'template' => '<div class="wrapper"><a>{view}</a> {update} {delete}</div>'
Finally your grid view will come some thing like
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$dataProvider,
..................
..................
'columns'=>array(
...............
...............
'template' => '<div class="wrapper"><a>{view}</a> {update} {delete}</div>',
...............
)
));
Please customize your CGridView buttons on views file like this.
$this->widget('zii.widgets.grid.CGridView', array(
---
'columns'=>array(
---
array(
'class'=>'CButtonColumn',
'template' => '<div class="wrapper">{view}{update}{delete}</div>',
),
),
));

yii data retrival query [duplicate]

I am new to yii framework i have created an yii web application with one module .
Now my question is i have added an sample data into my module in my module i have an columns name,dept and and active ,i want to render the data in the grid view only the data where active=0 , Can anyone help me how to change the data rendering query and how to add the condition
<div class="block">
<div class="content">
<h2 class="title">Users's details</h2>
<div class="inner">
<?php $this->widget('zii.widgets.CDetailView', array(
'data' => $model,
'attributes' => array(
'user_id',
'user_name',
'userpass',
'userdept',
'active',
),
'itemTemplate' => "<tr class=\"{class}\"><td style=\"width: 120px\"><b>{label}</b></td><td>{value}</td></tr>\n",
'htmlOptions' => array(
'class' => 'table',
),
)); ?>
</div>
</div>
Thanks in advance.
Try adding a criteria
$criteria->compare('active', '1');
You have to add this in your search function:
$criteria->compare('active', '1');