I have a variable $paginator for paginating data
In my Controller
public $paginator = [
'limit'=>5,
'order'=>[
'author'=>'desc'
]
];
In my view-template (.ctp)
<?= $this->Paginator->prev('<< pre') ?>
<?= $this->Paginator->next('next >>')?>
<?= $this->Paginator->counter() ?>
But i receive many error:
Notice (8): Undefined index: pageCount [CORE/src/View/Helper/PaginatorHelper.php, line 591]
Notice (8): Undefined index: count [CORE/src/View/Helper/PaginatorHelper.php, line 595]
Notice (8): Undefined index: perPage [CORE/src/View/Helper/PaginatorHelper.php, line 598]
Notice (8): Undefined index: count [CORE/src/View/Helper/PaginatorHelper.php, line 599]
Notice (8): Undefined index: count [CORE/src/View/Helper/PaginatorHelper.php, line 600]
Notice (8): Undefined index: page [CORE/src/View/Helper/PaginatorHelper.php, line 613]
Notice (8): Undefined index: current [CORE/src/View/Helper/PaginatorHelper.php, line 615]
Notice (8): Undefined index: count [CORE/src/View/Helper/PaginatorHelper.php, line 616]
I recognize that only this row cause error
<?= $this->Paginator->counter() ?>
i can't paginate.
why does it such? :(
In controller paginate property
public $paginate = [
'States' => ['scope' => 'states'],
'Lgas' => ['scope' => 'lgas'],
];
In controller action
$lgas = $this->paginate($this->Lgas, ['scope' => 'lgas']);
$states = $this->paginate($this->States, ['scope' => 'states']);
$this->set(compact('lgas', 'states'));
In View
<div class="paginator">
<ul class="pagination">
<?=$this->Paginator->first('<< ' . __('first'), ['model' => 'Lgas', 'tab' => 'lga'])?>
<?=$this->Paginator->prev('< ' . __('previous'), ['model' => 'Lgas', 'tab' => 'lga'])?>
<?=$this->Paginator->numbers(['model' => 'Lgas', 'tab' => 'lga'])?>
<?=$this->Paginator->next(__('next') . ' >', ['model' => 'Lgas', 'tab' => 'lga'])?>
<?=$this->Paginator->last(__('last') . ' >>', ['model' => 'Lgas', 'tab' => 'lga'])?>
</ul>
<p><?=$this->Paginator->counter(['format' => __('Page {{page}} of {{pages}}, showing {{current}} record(s) out of {{count}} total'), 'model' => 'Lgas', 'tab' => 'lga'])?></p>
</div>
<div class="paginator">
<ul class="pagination">
<?=$this->Paginator->first('<< ' . __('first'), ['model' => 'States'])?>
<?=$this->Paginator->prev('< ' . __('previous'), ['model' => 'States'])?>
<?=$this->Paginator->numbers(['model' => 'States'])?>
<?=$this->Paginator->next(__('next') . ' >', ['model' => 'States'])?>
<?=$this->Paginator->last(__('last') . ' >>', ['model' => 'States'])?>
</ul>
<p><?=$this->Paginator->counter(['format' => __('Page {{page}} of {{pages}}, showing {{current}} record(s) out of {{count}} total'), 'model' => 'States'])?></p>
</div>
Related
I am working a yii2 page and it's giving me problems adding a placeholder or a prompt to Select2 Widget. Here is my code:
<?php
use yii\helpers\Html;
use kartik\widgets\ActiveForm;
use kartik\builder\Form;
use kartik\datecontrol\DateControl;
use yii\helpers\ArrayHelper;
/**
* #var yii\web\View $this
* #var app\models\FinancialAccounts $model
* #var yii\widgets\ActiveForm $form
*/
?>
<div class="financial-accounts-form">
<?php $form = ActiveForm::begin(['type' => ActiveForm::TYPE_VERTICAL]); echo Form::widget([
'model' => $model,
'form' => $form,
'columns' => 1,
'attributes' => [
'type_id' => ['type' => Form::INPUT_WIDGET, 'widgetClass'=>'\kartik\widgets\Select2', 'options' => ['data'=>ArrayHelper::map(app\models\FinancialAccountType::find()->all(), 'type_id', 'name')]],
'account_name' => ['type' => Form::INPUT_TEXT, 'options' => ['placeholder' => 'Enter Account Name...', 'maxlength' => 100]],
'account_code' => ['type' => Form::INPUT_TEXT, 'options' => ['placeholder' => 'Enter Account Code...', 'maxlength' => 10]],
'parent_id' => ['type' => Form::INPUT_WIDGET, 'widgetClass'=>'\kartik\widgets\Select2', 'options' => ['data'=>ArrayHelper::map(app\models\FinancialAccounts::find()->all(), 'account_id', 'account_name'), 'placeholder' => 'Select a Parent Account...']],
'description' => ['type' => Form::INPUT_TEXT, 'options' => ['placeholder' => 'Enter Description...', 'maxlength' => 250]],
],
]);
echo Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'),
['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']
);
ActiveForm::end(); ?>
</div>
The problem is in the parent_id attribute as I cannot add a placeholder as an option as most of the tutorials recommend. Everytime I try that, I get an error as this:
Unknown Property – yii\base\UnknownPropertyException
Setting unknown property: kartik\widgets\Select2::placeholder
Does anyone know how I can solve this? My main problem is that I cannot leave this option as blank when submitting data yet that is one of the possibility. It forces me to submit an item selected.
You'll note that if you follow the examples in the documentation carefully, placeholder needs to be wrapped within an options array.
'parent_id' => [
'type' => Form::INPUT_WIDGET,
'widgetClass' => '\kartik\widgets\Select2',
'options' => [
'data' => ArrayHelper::map(app\models\FinancialAccounts::find()
->all(), 'account_id', 'account_name'),
'options' => ['placeholder' => '...'],
'pluginOptions' => ['allowClear' => true],
]
],
I am using kartik yii2 widget fileinput. I set 'maxFileSize' to 1024. When uploaded file exceeds maximum allowed size, error message shows up, I want to change this error text and show it in Georgian language. How can I achieve this?
Here is my code:
<?= $form->field($model, 'photo_name')->widget(FileInput::classname(), [
'options'=>[
'id'=>'upload-img',
'multiple'=>false,
'accept'=>'image/*',
],
'pluginOptions'=>[
'allowedFileExtensions'=>['jpg', 'gif', 'png', 'bmp'],
'browseLabel'=>'browse',
'captionLabel'=> '',
'removeLabel'=>'remove',
'browseClass' => 'btn btn-success',
'uploadClass' => 'btn btn-info',
'removeClass' => 'btn btn-danger',
'showPreview' => true,
'showCaption' => false,
'showRemove' => true,
'showUpload' => false,
'overwriteInitial'=>false,
'dropZoneEnabled'=>false,
'showClose' => false,
'browseIcon' => '<i class="glyphicon glyphicon-camera"></i> ',
'maxFileSize'=>1024
],
]); ?>
I need to change this error message:
You just need add this line into 'pluginOptions' and custom it:
<?= $form->field($model, 'photo_name')->widget(FileInput::classname(), [
'options'=>[
'id'=>'upload-img',
'multiple'=>false,
'accept'=>'image/*',
],
'pluginOptions'=>[
.
.
.
'msgSizeTooLarge' => 'File "{name}" (<b>{size} KB</b>) exceeds maximum allowed upload size of <b>{maxSize} KB</b>.',
],
]); ?>
You need to use the tooBig option inside the model validation rule where you specify the maxSize of the file your rule should look like below
[[ 'photo_name'] , 'file' , 'extensions' => 'pdf, jpg' , 'maxSize' => 1024000 , 'tooBig' => 'Limit is 1024KB' ] ,
For displaying it in georgian or any other than english you should look into the Message Translation
I have 2 modals in one active form. Let's say first one is modal-ticket and second one is contract-ticket. First time, I click button to show modal-ticket, and it was fine, but when I click button to show modal-contract, it also call script modal-ticket or otherwise. why?
this is my code.
<?php $form = ActiveForm::begin(); ?>
<div id="BtnSearchTicket">
<?= Html::button('Search Ticket', [
'value' => Url::to('../ticket-timbangan/list'),
'class' => 'btn btn-primary',
'id' => 'BtnModalTicketList',
'data-toggle'=>"modal",
'data-target'=>"#modalTicketList",
]) ?>
</div>
<div id="BtnSearchContract">
<?= Html::button('Search Contract', [
'value' => Url::to('../contract/list'),
'class' => 'btn btn-primary',
'id' => 'BtnModalContractList',
'data-toggle'=>"modal",
'data-target'=>"#modalContractList",
]) ?>
</div>
<?php ActiveForm::end(); ?>
<?php
Modal::begin([
'header' => 'Ticket List',
'id' => 'modalTicketList',
'size' => 'modal-lg',
'class' => 'style=width:auto'
]);
echo "<div id='modalContentTicket'></div>";
Modal::end();
?>
<?php
Modal::begin([
'header' => 'Contract List',
'id' => 'modalContractList',
'size' => 'modal-lg',
'class' => 'style=width:auto'
]);
echo "<div id='modalContentContract'></div>";
Modal::end();
?>
<?php
$script = <<< JS
$('#BtnModalTicketList').click(function(e){
e.preventDefault();
$('#modalTicketList').modal('show')
.find('#modalContentTicket')
.load($(this).attr('value'));
return false;
});
$('#BtnModalContractList').click(function(e){
e.preventDefault();
$('#modalContractList').modal('show')
.find('#modalContentContract')
.load($(this).attr('value'));
return false;
});
JS;
$this->registerJs($script);
?>
this are the error found in console web browser
GET http://localhost/pks/web/ticket-timbangan/get-ticket?id=1 404 (Not Found)
GET http://localhost/pks/web/contract/get-contract?id=2 404 (Not Found)
please help.
Try This: using one modal on your form:
<?php $form = ActiveForm::begin(); ?>
<div id="BtnSearchTicket">
<?= Html::button('Search Ticket', [
'value' => Url::to('../ticket-timbangan/list'),
'class' => 'btn btn-primary showModal',
'id' => 'BtnModalTicketList',
'title' => 'Search Ticket',
]) ?>
</div>
<div id="BtnSearchContract">
<?= Html::button('Search Contract', [
'value' => Url::to('../contract/list'),
'class' => 'btn btn-primary showModal',
'title' => 'Search Contract',
'id' => 'BtnModalContractList',
]) ?>
</div>
<?php ActiveForm::end(); ?>
<?php
Modal::begin([
'headerOptions' => ['id' => 'modalHeader'],
'id' => 'modal',
'size' => 'modal-lg',
'closeButton' => [
'id'=>'close-button',
'class'=>'close',
'data-dismiss' =>'modal',
],
'class' => 'style=width:auto',
'clientOptions' => [
'backdrop' => false, 'keyboard' => true
]
]);
echo "<div id='modalContent'></div>";
Modal::end();
?>
<?php
$script = <<< JS
$(document).on('click', '.showModal', function(){
if ($('#modal').hasClass('in')) {
$('#modal').find('#modalContent')
.load($(this).attr('value'));
document.getElementById('modalHeader').innerHTML = '<h4>' + $(this).attr('title') + '</h4>';
} else {
$('#modal').modal('show')
.find('#modalContent')
.load($(this).attr('value'));
document.getElementById('modalHeader').innerHTML = '<h4>' + $(this).attr('title') + '</h4>';
}
});
JS;
$this->registerJs($script);
?>
From viewing your code what calls my attention is how you use the Url::to() function. Not sure why you use ../. I have fiddled with using more than one modal in a form and the code is similar to what your are doing. I suggest you try changing your Url::to() function as follows:
Url::to('/ticket-timbangan/list')
and
Url::to('/contract/list')
Another suggestion would be to try with
Yii::$app->urlManager->createUrl('/ticket-timbangan/list')
and
Yii::$app->urlManager->createUrl('/contract/list')
Let me know if this helps.
First, many thanks to kalu who has helped me 2 days to solve my problem. Two modals which contains grid need to define different classes to prevent execute previous script.
'value' => Url::to('../ticket-timbangan/list') and 'value' => Url::to('../contract/list'), both has two gridview and same select-row class. This class is root cause of the problem, because it's same class and execute both script.
Thanks Kalu, you save my day.
all developer kartik\DepDrop widget The ability to use without model
My code this but error
use kartik\widgets\DepDrop;
<?php echo DepDrop::widget([
'options' => ['id'=>'customer-city'],
'pluginOptions' => [
'depends => ['province'],
'placeholder => 'select ...',
'url' => Url::to(['/site/city'])
]
]); ?>
I use this code for show dropdown without lable
Yes, for it you need set the attribute name:
<?php echo DepDrop::widget([
'name' => 'city',
'options' => ['id'=>'customer-city'],
'pluginOptions' => [
'depends' => ['province'],
'placeholder' => 'select ...',
'url' => Url::to(['/site/city'])
]
]); ?>
Is it possible to insert custom html code into a options name with Bootstraps formhelper?
<?php
echo $this->BootstrapForm->input('where', array(
'options' => array('1' => 'foo'),
'type' => 'radio'
));
?>
I would like it to be
<?php
echo $this->BootstrapForm->input('where', array(
'options' => array('1' => '<span class="italic">f</span>oo'),
'type' => 'radio'
));
?>
But when I insert the code it's being stripped from the output.
Im not sure which BoostrapForm helper you are using, but have you considered putting a flag escape as false ?
<?php
echo $this->BootstrapForm->input('where', array(
'options' => array('1' => '<span class="italic">f</span>oo'),
'type' => 'radio',
'escape' => false,
));
?>