Yii get pagesize in view of ClistView - php

How would i get the current pagesize in my View? I want to be able to add a banner when half the pagesize is reached.
If the page size is 10, insert a banner at position 5
i tried adding this in my view.php
if ($index == ($dataProvider->pagination->pageSize / 2)) { ... }
and this my index.php
$this->widget ( 'site.common.extensions.EListView.EListView', array (
'dataProvider' => $dataProvider,
'itemView' => '_view_gallery',
'pagerCssClass' => 'pagination',
'template' => '
<div class="row">
<div class="col-md-12">
<div class="row">
<div class="col-md-12">
<div class="pull-right">{sorter}</div>
<div class="pull-left"></div>
</div>
</div>
<div class="row">
<div class="col-md-12">{items}</div>
</div>
<div class="row padding-top-20px">
<div class="col-md-12">
{pager}
</div>
</div>
</div></div>',
'pager' => array (
'id' => '_pagination',
'class' => 'LinkPager',
'header' => '',
'htmlOptions' => array (
'class' => 'pagination'
)
),
'emptyText' => '<div class="alert alert-info">No result found.</div>'
)
);
but nothing happens.
I'm currently using this extension to create a perpage page size.
http://www.yiiframework.com/extension/elistview
also tried without using this extension, but still no luck. I'm using Yii 1.1.16.
any ideas?

In your _view_gallery.php you can use special variables available for CListView and CGridView (http://www.yiiframework.com/wiki/252/special-variables-in-cgridview-and-clistview/) in order to get the pageSize.
That could look like this:
if($widget->dataProvider->pagination->pageSize == 10){
//do something here
}
Accessing $dataProvider directly won't result in anything because that variable means nothing to the view.

Related

yii2 disable validation on hidden fields

I have created a dev that is changed according to the selected radio button.
the dev has input fields:
<div id='div-cash' class="toHide" hidden="true">
<div class="row" >
<div class="col-md-4">
<?php echo $form->field($cash[0], 'form_get',[
'template' => '{label}<div class="input-group">{input}
<span class="input-group-addon">pt</span></div>{error}{hint}',
'options' => ['class' => 'form-inline toHide cashtoHide', 'style' => 'margin-top:2rem'],
'labelOptions' => ['style' => 'margin-right:2rem'],
])->textInput();?>
</div>
</div>
</div>
when I submit the form the inputs of the other options are validated and I want to disable it
I used Conditional Validation to solve this problem
'whenClient' => "function (attribute, value) {
return $('input[type=radio]:checked').val() == 'cash';
}"

Yii2: Need to click submit button twice, name and id is not "submit"

Problem: I have three forms in one page, that all have the same bug: I need to click the submit button twice in order to submit the form.
I have discovered that this is a common bug and usually triggered by naming the button "submit", however this is not the case.
Here's my code:
(First form: Change Password)
<div id="change-password-form">
<?php $changePasswordForm = ActiveForm::begin([
'id' => 'change-password-form',
"options" => ["class" => "animated-label"],
"fieldConfig" => ["template" => "{input}\n{label}\n{hint}\n{error}"],
]); ?>
<div class="row">
<div class="col-md-6">
<?= $changePasswordForm->field($changePassword, 'newPassword')->passwordInput() ?>
</div>
<div class="col-md-6">
<?= $changePasswordForm->field($changePassword, 'repeatNewPassword')->passwordInput() ?>
</div>
</div>
<div class="row">
<div class="col-md-6">
<?= $changePasswordForm->field($changePassword, 'oldPassword')->passwordInput() ?>
</div>
<div class="col-md-6">
<?= Html::submitButton(
'Change Password',
[
'class' => 'btn btn-primary',
"style" => "width: 100%",
'name' => 'submit-change-password',
'id' => 'submit-change-password',
]
) ?>
</div>
</div>
<?php ActiveForm::end(); ?>
</div>
(Second form: Change Email)
<div id="change-email-form">
<?php $changeEmailForm = ActiveForm::begin([
'id' => 'change-email-form',
"options" => ["class" => "animated-label"],
"fieldConfig" => ["template" => "{input}\n{label}\n{hint}\n{error}"],
]); ?>
<div class="row">
<div class="col-md-6">
<?= $changeEmailForm->field($changeEmail, 'password')->passwordInput() ?>
</div>
<div class="col-md-6">
<?= $changeEmailForm->field($changeEmail, 'email')->textInput() ?>
</div>
</div>
<div class="row">
<div class="col-md-6 col-md-offset-6">
<?= Html::submitButton(
'Change Email',
[
'class' => 'btn btn-primary',
"style" => "width: 100%",
'name' => 'submit-change-email',
'id' => 'submit-change-email',
]
) ?>
</div>
</div>
<?php ActiveForm::end(); ?>
</div>
(Third form: Change Username)
<div id="change-username-form">
<?php $changeUsernameForm = ActiveForm::begin([
'id' => 'change-username-form',
"options" => ["class" => "animated-label"],
"fieldConfig" => ["template" => "{input}\n{label}\n{hint}\n{error}"],
]); ?>
<div class="row">
<div class="col-md-6">
<?= $changeUsernameForm->field($changeUsername, 'password')->passwordInput() ?>
</div>
<div class="col-md-6">
<?= $changeUsernameForm->field($changeUsername, 'username')->textInput() ?>
</div>
</div>
<div class="row">
<div class="col-md-6 col-md-offset-6">
<?= Html::submitButton(
'Change Username',
[
'class' => 'btn btn-primary',
"style" => "width: 100%",
'name' => 'submit-change-username',
'id' => 'submit-change-username',
]
) ?>
</div>
</div>
<?php ActiveForm::end(); ?>
</div>
As you can see, the submit buttons have both unique IDs and names, they are correctly resolved to the desired HTML code.
E.g. the submit button of "change password" looks like this:
<button type="submit" id="submit-change-password" class="btn btn-primary" name="submit-change-password" style="width: 100%">Change Password</button>
Are there any solutions or workarounds for this case? I have only found the solution about renaming the submit buttons.
for anyone looking for an answer to this particular situation, in my case, I solve it by removing the extra attribute on the active form begin part.
Example: Before
ActiveForm::begin(['id' => 'registration-form'])
After
ActiveForm::begin()
Now I am not really sure, how this was causing the problem. I have other forms in which I have the extra attributes and it works completely fine on those forms. I check the console for errors but could not find any. My guess is on my particular form with this issue, I was using external js file required for plugin and somehow it was causing some kind of conflict with yii validation or bootstrap js files.

Mulit select widget post large data in form

I am using XMultiSelects Widget to post large data in form.(Yii Framework)
<div class="row">
<?php echo $form->labelEx($model, 'list'); ?>
<div style="display: inline-block">
<?php
$this->widget('multiselects.XMultiSelects', array(
'id' => 'hd-programs', //since there are multiple selector pairs on this page we need to set identifier
'leftTitle' => 'Available',
'leftName' => 'availableList',
'leftList' => $availableList,
'rightTitle' => 'Selected',
'rightName' => get_class($model) . '[list][]',
'rightList' => $list,
'size' => 15,
'width' => '350px',
));
?>
<?php echo $form->error($model, 'list'); ?>
</div>
where $avaliableList is very large data set.
Now when i print value of form using print_r($_Post['MyFormName']) $list is not posted.
Any suggestion how could i handle large data with multiselect widget.

Yii Sort By Clistview not working

I'm using Yii 1.1.15. I got to my CListView to populate the table correctly on page load. but when i try to sort the table by store name the ajax response is the html for the whole page. and the table is empty.
but when i refresh the page &sort=store or &sort=store.desc the page works fine and sorts proper too. Any ideas what i'm doing wrong?
In my Controller
$dataProvider=new CActiveDataProvider('Store',
array(
'criteria' => array(
'condition'=>$_search_conditions,
'params'=>$search_params,
),
'sort'=>array(
'defaultOrder'=>'store DESC',
'attributes'=>array(
'store'=>array(
'asc'=>'store',
'desc'=>'store DESC',
),
'*',
)
),
)
);
$model = new Store;
$model->unsetAttributes(); // clear any default values
//render page
$this->render('index',array(
'dataProvider'=>$dataProvider,
'model'=>$model
));
In my View
$this->widget('zii.widgets.CListView', array(
'id' => 'store-list',
'dataProvider'=>$dataProvider,
'itemView'=>'_view',
'enableHistory'=> true,
'pagerCssClass' => 'pagination',
'ajaxUpdate'=>'store-list',
'loadingCssClass' => '', //remove loading icon
'sortableAttributes'=>array(
'store',
//'state' => 'State',
//'distance' => 'Distance'
),
'emptyText' => '<div class="alert alert-info">No data found</div>',
'template'=>'
<div class="row">
<div class="col-md-12">
<div class="pull-left visible-lg visible-md visible-sm">{summary}</div>
<div class="pull-right">{sorter}</div>
</div>
</div>
<div class="row">
<div class="col-md-12">{items}</div>
</div>
<div class="row">
<div class="col-md-12">
{pager}
</div>
</div>',
'pager' => array('id'=>'_pagination',
'class' => 'LinkPager',
'header' => '', //remove pagination header
'htmlOptions'=>array('class'=>'pagination') //add bootstrap pagination class
),
));
also in my function parseUrl() i have this code which does echo the correct value for $_GET['Store_sort'] the code below is used in my custom url manager class
if (!empty($_GET['sort']))
{
echo $_GET['Store_sort'] = $_GET['sort'];
}
UPDATE: even with friendly url disabled it does not sort. here is the URL of the ajax post. The pagination doesnt work either
http://localhost/dev/frontend/www/store/store/index/?Store_sort=store.desc&ajax=store-list

Codeigniter form_error with Bootstrap 3

Hello guys I am doing a form in codeigniter to display error message. My CSS framework is Bootstrap 3.
My codes so far:
View.php
<div class="form-group">
<?php
$label_attributes = array('class' => 'col-sm-2 control-label');
echo form_label('Load Balance', 'load_balance', $label_attributes);
?>
<div class="col-xs-3">
<?php
$load_balance_attrs = array('class' => 'form-control',
'id' => 'load_balance',
'placeholder' => 'Load Balance',
'name' => 'load_balance',
'type' => 'number',
'min' => '0',
'step' => '1', );
echo form_input($load_balance_attrs);
?>
<?php echo form_error('load_balance',
'<span class="glyphicon glyphicon-remove form-control-feedback"></span>
<p class="help-block">', '</p>'); ?>
</div>
</div>
I am trying to get this example but I have no idea how to append .has-error to my .form-group to display the error message. Do you have any ideas how to do that? Your help will be greatly appreciated. Thanks.
You may try something like this:
<div class="form-group <?php if(validation_errors()) echo 'has-error'; ?>">
Instead of:
<div class="form-group">

Categories