It is possible to create
href="controller action"
with id of model?
I have this code and i want to use html href to actions of controller.
<?php
use yii\helpers\Html;
use yii\helpers\Url;
?>
<div class="news">
<div class="context-menu">
<i class="icon-circle-down"></i>
<ul class="dropdown-menu" aria-labelledby="dropdownProfile">
<li>Lorem ipsum</li>
<li>Lorem ipsum</li>
</ul>
</div>
<div class="header-news">
<img src="<?= Url::base(true) ?>/img/ania.jpg" alt="">
<p class="author"><?= $model->getUser($model->urUser_Id); ?></p>
<p class="date"><?= $model->CreatedAt; ?></p>
</div>
<div class="content-news">
<p><?= $model->Text; ?></p>
</div>
<?= $model->getStatus($model->cnNewsContentType_Id); ?> <br>
<?php
if ($model->getId($model->urUser_Id) == Yii::$app->user->identity->Id) {
echo Html::a(Yii::t('app', 'Edytuj'), ['update', 'id' => $model->Id], ['class' => 'btn btn-primary']);
echo Html::a(Yii::t('app', 'Usuń'), ['delete', 'id' => $model->Id], [
'class' => 'btn btn-danger',
'data' => [
'confirm' => Yii::t('app', 'Jesteś pewien, że chcesz usuńąć tego newsa?'),
'method' => 'post',
],
]);
}
?>
</div>
There is dropdown list in html where i want to paste link of actions of my controller.
<li>Lorem ipsum</li>
<li>Lorem ipsum</li>
There instead of # i want to use this action edit and delete it is possible?
<li>
<?php echo Html::a(Yii::t('app', 'yourItemLabel'),
Url::to(['/yourController/yourAction',
'id' => $model->id]), ['class' => 'btn btn-primary']) ?>
</li>;
or you can simply assign an url to your href
this sample is for a relative path
echo '<a href="./index.php/myController/myActio/?id=1"
class="btn btn-success btn-block">mylinktext</a>';
Related
I have two activeform in my view and one of them use pjax. And both of them requires second click to submit. I don't know what I am doing wrong. I search this problem in internet, but meet other cases of second click
<?php Pjax::begin(['id' => 'workers', "timeout" => 50000], ["options" => ["timeout" => 5000]]);?>
<?php
echo $this->render('_show', [
"model" => $searchModel,
"filials" => $filials,
"workers" => $workers,
"posts" => $posts,
]);
echo $this->render('_handle_form');
?>
<div class="row js-loader">
<div class="col-lg-12 col-md-12">
<div class="table-responsive">
<?=GridView::widget([
'dataProvider' => $dataProvider,
'emptyText' => 'Нет результатов',
'tableOptions' => ['class' => 'table table-hover table-claim table-claimadm', 'style' => 'font-weight:600;'],
'rowOptions' => ['class'=>'row-without-border row-open'],
'layout' => "{items}{pager}",
'columns' => [
[
...
]
]);?>
</div>
</div>
</div>
<?php Pjax::end();?>
<script>
window.onload = function () {
$(document).on('pjax:send', function (event) {
tbody = $('#' + event.target.id).find(".js-loader");
if (tbody.length != 0) {
tbody_height = tbody.height();
tbody.html('<div class="block-loader" style="width:100%"></div>');
}
});
$('#submit_with_answer').click(function() {
if ($.trim($('#text-claim').val()).length > 0)
{
$('#complaint_feedback').submit();
}
else
{
$('#textarea-group').addClass('has-error');
$('#answer_error').html('Заполните поле «Добавить текст ответа»');
}
});
};
</script>
The "_show" view is:
<?php $form = ActiveForm::begin([
'id' => 'complaints',
'action' => Url::to(['complaints/show']),
'method' => 'GET',
'options' =>
[
'class' => 'form-respons form-claimadm',
'data-pjax' => 1,
],
]);
active fields....
<div class="form-btns col-md-2 col-sm-6 col-xs-12">
<?= Html::submitButton('Применить', ['class' => 'btn btn-primary','style'=>"float:right;"]) ?>
</div>
</div>
<?php ActiveForm::end(); ?>
and _handle_form is:
<?php
use yii\widgets\ActiveForm;
use yii\helpers\Url;
?>
<?php
$form = ActiveForm::begin([
'id' => 'complaint_feedback',
'action' => Url::to(['complaints/handle-complaint']),
'method' => 'POST',
'options' => ['class' => 'form-respons form-claim-feedback','style'=>'display:none;'],
]);
?>
<div id="textarea-group" class="form-group">
<label for="text-claim" class="hidden-xs">Добавить текст ответа</label>
<textarea class="form-control" id="text-claim" rows="3" name="complaint_answer" placeholder="Добавить текст ответа"></textarea>
<div id="answer_error" class="help-block"></div>
<input id="complaint_id" name="complaint_id" type="hidden" value="">
</div>
<div class="clearfix form-btns">
<button type="button" onclick="$('#complaint_feedback').submit();" class="btn btn-link">Обработать без ответа</button>
<button id="submit_with_answer" type="button" class="btn btn-primary">Отправить</button>
</div>
<?php ActiveForm::end(); ?>
<a id="hide_handle_form" style="display: none;" onclick="$('#complaint_feedback').hide(); $('.handle_button').removeClass('disabled'); $(this).hide();$('tr[data-key='+$('#complaint_id').val()+']').removeClass('row-open');" class="btn btn-link btn-show-hide">Свернуть
</a>
if I comment lines with pjax, everything works correctly. How can I fix this trouble?
I have my dynamic form using wbraganca widget and kartik file upload inside it. When I open the page, the field was just showing spinner image instead of a textfield and the console display "unrecognized expression: #tcandidateexp-{$i}-prod_per_year_file". The field I want to use as a file upload is "prod_per_year_file". Any help would be appreciate. Thanks.
<?php $form = ActiveForm::begin(['id' => 'dynamic-form', 'options'=>['enctype'=>'multipart/form-data']]); ?>
<div class='row'>
<?php DynamicFormWidget::begin([
'widgetContainer' => 'dynamicform_wrapper', // required: only alphanumeric characters plus "_" [A-Za-z0-9_]
'widgetBody' => '.container-items', // required: css class selector
'widgetItem' => '.item', // required: css class
'limit' => 5, // the maximum times, an element can be added (default 999)
'min' => 1, // 0 or 1 (default 1)
'insertButton' => '.add-item', // css class
'deleteButton' => '.remove-item', // css class
'model' => $models_exp[0],
'formId' => 'dynamic-form',
'formFields' => [
'start_year',
'end_year',
'company',
'prod_per_year',
'prod_per_year_file',
'inc_per_year',
'inc_per_year_file'
],
]); ?>
<div class="panel panel-default" style="width:85%">
<div class="panel-heading">
<h4>
<i class="glyphicon glyphicon-envelope"></i> Experiences
<button type="button" class="add-item btn btn-success btn-sm pull-right"><i class="glyphicon glyphicon-plus"></i> Add</button>
</h4>
</div>
<div class="panel-body">
<div class="container-items"><!-- widgetBody -->
<?php foreach ($models_exp as $i => $model_exp): ?>
<div class="item panel panel-default"><!-- widgetItem -->
<div class="panel-heading">
<h3 class="panel-title pull-left">Detail</h3>
<div class="pull-right">
<button type="button" class="remove-item btn btn-danger btn-xs"><i class="glyphicon glyphicon-minus"></i></button>
</div>
<div class="clearfix"></div>
</div>
<div class="panel-body">
<?php
// necessary for update action.
if (! $model_exp->isNewRecord) {
echo Html::activeHiddenInput($model_exp, "[{$i}]id");
}
?>
<div class="row">
<div class="col-sm-6" >
<?=
$form->field($model_exp, "[{$i}]start_year")->textInput();
?>
</div>
<div class="col-sm-2">
<?=
$form->field($model_exp, "[{$i}]end_year")->textInput();
?>
</div>
<div class="col-sm-2">
<?=
$form->field($model_exp, "[{$i}]company")->textInput();
?>
</div>
<div class="col-sm-10">
<?= $form->field($model_exp, "[{$i}]prod_per_year")->textInput() ?>
</div>
<div class="col-sm-10">
<?php
//$form->field($model_exp, "[{$i}]prod_per_year_file")->textInput()
echo $form->field($model_exp, '[{$i}]prod_per_year_file')->widget(FileInput::classname(), [
'pluginOptions' => [
'showPreview' => false,
'showCaption' => true,
'showRemove' => true,
'showUpload' => false
]
]);
?>
</div>
<div class="col-sm-10">
<?= $form->field($model_exp, "[{$i}]inc_per_year")->textInput() ?>
</div>
<div class="col-sm-10">
<?= $form->field($model_exp, "[{$i}]inc_per_year_file")->textInput() ?>
</div>
</div><!-- .row -->
</div>
</div>
<?php endforeach; ?>
</div>
</div>
</div><!-- .panel -->
<?php DynamicFormWidget::end(); ?>
</div>
Try replace the single quotes with double quotes
echo $form->field($model_exp, "[{$i}]prod_per_year_file")->widget(FileInput::classname(), [
'pluginOptions' => [
'showPreview' => false,
'showCaption' => true,
'showRemove' => true,
'showUpload' => false
]
]);
I have a page which consist of 5 tab. 1st and 2nd tab is just normal filling form while my 3rd,4th and 5th tab is the index of other index page (which I can create update and delete the data). Below is the code for the form.
<?php
use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
use kartik\tabs\TabsX;
use kartik\date\DatePicker;
use frontend\models\OpStates;
use frontend\models\OpContact;
use frontend\models\OpCountries;
use frontend\models\OpClient;
use frontend\models\OpUnit;
use frontend\models\OpMaintenanceCharges;
use yii\helpers\ArrayHelper;
use yii\helpers\Url;
$this->title = 'Change Profile';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="site-changedetails">
<?php $form = ActiveForm::begin(['id'=>'changedetails-form',]); ?>
<?= TabsX::widget([
'position' => TabsX::POS_ABOVE,
'align' => TabsX::ALIGN_LEFT,
'items' => [
[
'label'=>'Client Details',
'content'=>
'<div class="row">
<div class="col-md-12">'.
$form->field($model, "client_code")->textInput(["maxlength" => true]).'
</div>
</div>
<div class="row">
<div class="col-md-12">'.
$form->field($model, "contact_id")->dropDownList(ArrayHelper::map(OpContact::find()->all(),'id','code')).'
</div>
</div>
<div class="row">
<div class="col-md-12">'.
$form->field($model, "unit_id")->dropDownList(ArrayHelper::map(OpUnit::find()->all(),'id','code')).'
</div>
</div>
<div class="row">
<div class="col-md-12">'.
$form->field($model, 'country_id')->dropDownList(ArrayHelper::map(OpCountries::find()->all(),'id','name'),
[
'prompt' => 'Select Country',
'onchange' => '
$.post("index.php?r=op-states/lists&id='.'" + $(this).val(), function(data){
$("select#opclient-states_id").html(data);
});'
]).'
</div>
</div>
<div class="row">
<div class="col-md-12">'.
$form->field($model, 'states_id')->dropDownList(ArrayHelper::map(OpStates::find()->all(),'id','state_name'),
[
'prompt' => 'Select States',
]).'
</div>
</div>
<div class="row">
<div class="col-md-6">'.
$form->field($model, 'city')->textInput(['maxlength' => true]).'
</div>
<div class="col-md-6">'.
$form->field($model, 'postcode')->textInput().'
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-md-1 col-md-offset-11">'.
Html::submitButton('Save',['class'=>'pull-right btn btn-primary','style'=>'width:70px; height:40px;','name'=>'button1']).'
</div>
</div>
</div>
'
],
[
'label'=>'Client Details 2',
'content'=>
' <div class="row">
<div class="col-md-12">'.
$form->field($model, "charge_interest")->dropDownList(['Yes'=>'Yes','No'=>'No']).'
</div>
</div>
<div class="row">
<div class="col-md-12">'.
$form->field($model, 'interest_effective_date')->widget(DatePicker::classname(), [
'pluginOptions' => [
'autoclose'=>true,
'format' => 'yyyy-mm-dd',
'todayHighlight' => true,
'todayBtn' => true,
]
]).'
</div>
</div>
<div class="row">
<div class="col-md-12">'.
$form->field($model, "charge_reminder")->dropDownList(['Yes'=>'Yes','No'=>'No']).'
</div>
</div>
<div class="row">
<div class="col-md-12">'.
$form->field($model, "external_debtor_code")->textInput().'
</div>
</div>
<div class="row">
<div class="col-md-12">'.
$form->field($model, "mailing_address1")->textInput().'
</div>
</div>
<div class="row">
<div class="col-md-12">'.
$form->field($model, "mailing_address2")->textInput().'
</div>
</div>
<div class="row">
<div class="col-md-12">'.
$form->field($model, "mailing_address3")->textInput().'
</div>
</div>
<div class="row">
<div class="col-md-12">'.
$form->field($model, "mailing_address4")->textInput().'
</div>
</div>
'
],
[
'label'=>'Maintenance Charges',
'content' => $this->render('//op-maintenance-charges/index', [
'model'=>$model,
'dataProviderMainCharges' => $dataProviderMainCharges,
]),
],
[
'label'=>'Misc Charges',
'content' => $this->render('//op-misc-charges/index', [
'model'=>$model,
'dataProviderMiscCharges' => $dataProviderMiscCharges,
]),
],
[
'label'=>'Occupier Details',
'content' => $this->render('//op-occupier/index', [
'model'=>$model,
'dataProviderOccupier' => $dataProviderOccupier,
]),
],
]
]); ?>
<?php ActiveForm::end(); ?>
The problem is the 1st index page is working normally. Click to see - Working normally
The 2nd index page n 3rd index cannot work. The form wont even come out. The screen just become darker and I cant click anything like this Click to see - Cant Work
Anyone can help or have any idea on how to fix it? Thanks
I want to make a dropdown button and when I tried to make it, the position of dropdown list not in the center.
Here is my code:
<?php
use yii\helpers\Url;
use yii\helpers\Html;
use yii\bootstrap\Dropdown;
/* #var $this yii\web\View */
?>
<div class="site-index">
<div class="jumbotron">
<h1>Selamat Datang!</h1>
<p class="lead-lg-5">
Aplikasi ini ditujukan untuk menampilkan <br>
data-data dan statistik mahasiswa program Pascasarjana Universitas
</p>
<div class="col-md-12 school-options-dropdown text-center">
<div class="dropdown btn-group"> <div class="btn btn-success btn-sm">
Pilih Tahun Periode<b class="caret"></b>
<?php
echo Dropdown::widget([
'items' => [
['label' => 'Periode 2001-2005', 'url' => "index.php?r=site%2Findexumum"],
['label' => 'Periode 2006-2010', 'url' => '#'],
['label' => 'Periode 2011-2015', 'url' => '#'],
],
]);
?>
</div>
</div>
</div>
</div>
</div>
Here is the result:
What may I do to solve that? Thanks in advance
I want to use dynamic form widget (wbraganca). I tried it using the tutorial by 'doingItEasy' channel & also by github. And wrote following code :
controller code -
public function actionCreate()
{
$model = new Vendors();
$modelsSubCat = [new BusinessSubCategories];
if ($model->load(Yii::$app->request->post()) && $model->save()) {
$modelsSubCat = Model::createMultiple(BusinessSubCategories::classname());
Model::loadMultiple($modelsSubCat, Yii::$app->request->post());
// validate all models
$valid = $model->validate();
$valid = Model::validateMultiple($modelsSubCat) && $valid;
$modelsSubCat = Model::createMultiple(BusinessSubCategories::classname());
if ($valid) {
$transaction = \Yii::$app->db->beginTransaction();
try {
if ($flag = $model->save(false)) {
foreach ($modelsSubCat as $modelSubCat) {
$model->ven_sub_category_id = $modelSubCat->bsc_id;
if (! ($flag = $modelSubCat->save(false))) {
$transaction->rollBack();
break;
}
}
}
if ($flag) {
$transaction->commit();
return $this->redirect(['view', 'id' => $model->ven_id]);
}
} catch (Exception $e) {
$transaction->rollBack();
}
}
} else {
return $this->render('create', [
'model' => $model,
'modelsSubCat' => (empty($modelsSubCat)) ? [new BusinessSubCategories] : $modelsSubCat
]);
}
}
'_form.php' code -
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use wbraganca\dynamicform\DynamicFormWidget;
?>
<div class="vendors-form">
<?php $form = ActiveForm::begin(['id' => 'dynamic-form']); ?>
<?= $form->field($model, 'ven_company_name')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'ven_main_category_id')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'ven_sub_category_id')->textInput() ?>
<div class="row">
<div class="panel panel-default">
<div class="panel-body">
<?php DynamicFormWidget::begin([
'widgetContainer' => 'dynamicform_wrapper', // required: only alphanumeric characters plus "_" [A-Za-z0-9_]
'widgetBody' => '.container-items', // required: css class selector
'widgetItem' => '.item', // required: css class
'limit' => 4, // the maximum times, an element can be cloned (default 999)
'min' => 1, // 0 or 1 (default 1)
'insertButton' => '.add-item', // css class
'deleteButton' => '.remove-item', // css class
'model' => $modelsSubCat[0],
'formId' => 'dynamic-form',
'formFields' => [
// 'bsc_id',
'bsc_name',
'bsc_image',
'bsc_description',
'bmc_id',
],
]); ?>
<div class="container-items"><!-- widgetContainer -->
<?php foreach ($modelsSubCat as $i => $modelSubCat): ?>
<div class="item panel panel-default"><!-- widgetBody -->
<div class="panel-heading">
<h3 class="panel-title pull-left">Sub Categories</h3>
<div class="pull-right">
<button type="button" class="add-item btn btn-success btn-xs"><i class="glyphicon glyphicon-plus"></i></button>
<button type="button" class="remove-item btn btn-danger btn-xs"><i class="glyphicon glyphicon-minus"></i></button>
</div>
<div class="clearfix"></div>
</div>
<div class="panel-body">
<?php
// necessary for update action.
if (! $modelSubCat->isNewRecord) {
echo Html::activeHiddenInput($modelSubCat, "[{$i}]id");
}
?>
<?= $form->field($modelSubCat, "[{$i}]bsc_name")->textInput(['maxlength' => true]) ?>
<div class="row">
<div class="col-sm-6">
<?= $form->field($modelSubCat, "[{$i}]bsc_image")->fileInput(); ?>
</div>
<div class="col-sm-6">
<?= $form->field($modelSubCat, "[{$i}]bsc_description")->textInput(['maxlength' => true]) ?>
</div>
</div><!-- .row -->
</div>
</div>
<?php endforeach; ?>
</div>
<?php DynamicFormWidget::end(); ?>
</div>
</div>
<?= $form->field($model, 'ven_services_offered')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'ven_business_logo')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'ven_company_descr')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'ven_established_date')->textInput() ?>
<?= $form->field($model, 'ven_noof_emp')->textInput() ?>
<?= $form->field($model, 'ven_branches_loc')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'ven_market_area')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'ven_website')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'ven_specialized_in')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'ven_contact_no')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'ven_email_id')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'ven_address')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'ven_country_id')->textInput() ?>
<?= $form->field($model, 'ven_state_id')->textInput() ?>
<?= $form->field($model, 'ven_city_id')->textInput() ?>
<?= $form->field($model, 'ven_location_id')->textInput() ?>
<?= $form->field($model, 'ven_zip')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'ven_contact_person_id')->textInput() ?>
<?= $form->field($model, 'ven_verified')->dropDownList([ 'Y' => 'Y', 'N' => 'N', ], ['prompt' => '']) ?>
<?= $form->field($model, 'ven_created')->textInput() ?>
<?= $form->field($model, 'ven_updated')->textInput() ?>
<?= $form->field($model, 'ven_deleted')->dropDownList([ 'Y' => 'Y', 'N' => 'N', ], ['prompt' => '']) ?>
<div class="form-group">
<?= Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
<script type="text/javascript">
$(".dynamicform_wrapper").on("beforeInsert", function(e, item) {
console.log("beforeInsert");
});
$(".dynamicform_wrapper").on("afterInsert", function(e, item) {
console.log("afterInsert");
});
$(".dynamicform_wrapper").on("beforeDelete", function(e, item) {
if (! confirm("Are you sure you want to delete this item?")) {
return false;
}
return true;
});
$(".dynamicform_wrapper").on("afterDelete", function(e) {
console.log("Deleted item!");
});
$(".dynamicform_wrapper").on("limitReached", function(e, item) {
alert("Limit reached");
});
</script>
'create.php' code -
<?php
use yii\helpers\Html;
/* #var $this yii\web\View */
/* #var $model backend\models\Vendors */
$this->title = Yii::t('app', 'Create Vendors');
$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Vendors'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="vendors-create">
<h1><?= Html::encode($this->title) ?></h1>
<?= $this->render('_form', [
'model' => $model,
'modelsSubCat' => $modelsSubCat
]) ?>
</div>
But What happens is that the add/remove button is not working. I'm showing it's screenshot - Screenshot with Add/remove buttons
1)first add
$form = ActiveForm::begin([
'options' => [
'enctype' => 'multipart/form-data',
'id' => 'dynamic-form'
]
]);
instead your
2) delete 'bmc_id' from attributes of dynamic form or add textinput to dynamic form with bmc_id column
3) check if exist your model Model (...Model::loadMultiple($modelsSubCat, Yii::$app->request->post());)
I tried, but i can't reproduce this issue here. Can you try fix the following lines and see if the problem was there?
You are not closing the <div class="row"> after the dynamic form.
This could mess up the html code.
In your formFields, you don't need to add the 'bmc_id' if the
model have one. Remove it. By the way, you are using:
Html::activeHiddenInput($modelSubCat, "[{$i}]id");
Make sure this is the correct name of the attribute.
Non-related with your issue, you have a second:
$modelsSubCat = Model::createMultiple(BusinessSubCategories::classname());
After the loadMultiple method, making it useless.
EDIT
Just occurred to me: by any chance you have more than one DynamicForm in the same view? Or the code is the same as you posted?