Search the Community
Showing results for tags 'kartik'.
-
Hello, I want a form that create a "Feuille de jour" based on dropdownlist from other models. In fact, I have 4 tables that are linked by id : the table "Feuille de jour" have the id from the tables "poste FDJ", "categorie FDJ" and "personnel". When I create a "Feuille de jour", I want to be able to select (in a dropdown list) the name of a "poste FDJ", a "categorie FDJ" and a "personnel" and when I submit the form, it save the id of each name. I know it's possible to save multiple model in one form, I supposed that I can start on this but it doesn't work. Can someone help me? There are my create function controller (that had worked with a "simple" form) and my view : public function actionCreate() { $model = new FeuilleDeJourResponsable(); $meteo_prevision = new MeteoPrevision(); $poste_fdj = new PosteFdj(); $categorie_fdj = new CategorieFdj(); $personnel = new Personnel(); if ($model->load(Yii::$app->request->post()) && $meteo_prevision->load(Yii::$app->request->post()) && $poste_fdj->load(Yii::$app->request->post()) && $categorie_fdj->load(Yii::$app->request->post()) && $personnel->load(Yii::$app->request->post()) && FeuilleDeJourResponsable::validateMultiple([$model, $meteo_prevision, $poste_fdj, $categorie_fdj, $personnel])) { $poste_fdj->save(false); $categorie_fdj->save(false); $personnel->save(false); $model->ID_Poste_FDJ = $poste_fdj->ID_Poste_FDJ; // no need for validation rule on user_id as you set it yourself $model->ID_Categorie = $categorie_fdj->ID_Categorie; // no need for validation rule on user_id as you set it yourself $model->Code_Personnel = $personnel->Code_Personnel; // no need for validation rule on user_id as you set it yourself $model->save(false); // skip validation as model is already validated $meteo_prevision->Date_Calendaire = $model->Date_Calendaire; // no need for validation rule on user_id as you set it yourself $meteo_prevision->save(false); return $this->redirect(['feuille_de_jour_responsable/view', 'Date_Calendaire' => $model->Date_Calendaire]); } else { return $this->render('create', [ 'feuille_de_jour_responsable' => $model, 'meteo_prevision' => $meteo_prevision, 'poste_fdj' => $poste_fdj, 'categorie_fdj' => $categorie_fdj, 'personnel' => $personnel, ]); } } <?php $reqNomPoste = 'SELECT Nom_Poste_FDJ,ID_Poste_FDJ FROM poste_fdj'; $nomPoste = PosteFdj::findBySql($reqNomPoste) ->asArray() ->all(); /*$IDPoste = array(); $i = 0; foreach ($nomPoste["ID_Poste_FDJ"] as $ID) { $i++; $IDPoste = $ID; }*/ //var_dump($nomPoste); $reqNomPersonnel = 'SELECT Nom_Personnel,Code_Personnel FROM personnel'; $nomPersonnel = Personnel::findBySql($reqNomPersonnel) ->asArray() ->all(); //var_dump($nomPersonnel); $reqCategorie = 'SELECT Nom,ID_Categorie FROM categorie_fdj'; $categorie = CategorieFdj::findBySql($reqCategorie) ->asArray() ->all(); //var_dump($nomPersonnel); $form = ActiveForm::begin(); echo FormGrid::widget([ 'model'=>$feuille_de_jour_responsable, 'form'=>$form, 'autoGenerateColumns'=>true, 'rows'=>[ [ 'attributes'=>[ 'ID_Poste_FDJ'=>['type'=>Form::INPUT_DROPDOWN_LIST, 'items'=>PosteFdj::find()->select(['Nom_Poste_FDJ', 'ID_Poste_FDJ'])->indexBy('ID_Poste_FDJ')->column(), 'hint'=>'Choisir Poste'], //::findBySql('SELECT Nom_Poste_FDJ,ID_Poste_FDJ FROM poste_fdj'), 'hint'=>'Choisir Poste'] 'Code_Personnel'=>['type'=>Form::INPUT_DROPDOWN_LIST, 'items'=>Personnel::find()->select(['Nom_Personnel', 'Code_Personnel'])->indexBy('Code_Personnel')->column(),'hint'=>'Select Personnel'], 'ID_Categorie'=>['type'=>Form::INPUT_DROPDOWN_LIST, 'items'=>CategorieFdj::find()->select(['Nom', 'ID_Categorie'])->indexBy('ID_Categorie')->column(), 'hint'=>'Choisir Categorie'], ] ], [ 'attributes'=>[ //'Date_Calendaire'=>['type'=>Form::INPUT_TEXT, 'options'=>['placeholder'=>'Enter username...']], //'Date_Calendaire'=>['type'=>Form::INPUT_WIDGET, 'widgetClass'=>'\kartik\widgets\DatePicker', 'hint'=>'Enter birthday (mm/dd/yyyy)'], 'Date_Calendaire'=>['type'=>Form::INPUT_WIDGET, 'widgetClass'=>'\kartik\widgets\DatePicker', 'options' => [ 'pluginOptions' => [ 'todayHighlight' => true, 'format' => 'yyyy-mm-dd', 'multidate' => true, 'multidateSeparator' => ' ; ', ], ], 'hint'=>'Select Date', ], ] ], [ 'attributes'=>[ 'actions'=>[ // embed raw HTML content 'type'=>Form::INPUT_RAW, 'value'=> '<div>' . Html::resetButton('Reset', ['class'=>'btn btn-default']) . ' ' . Html::submitButton('Submit', ['class'=>'btn btn-primary']) . '</div>' ] ], ], ] ]); ?> <?php ActiveForm::end();?> Thank you ! =)
-
I want to be able to click on a link from the registration gridview, and filter the results of the players gridview so only the players I selected show up. Right now, it's not filtering. I get all the players. I have the following tables: - registrations - players From the registrations/index gridview I have a link so I can edit players: <?= DynaGrid::widget([ 'columns' => [ ['attribute'=>'playersEditLink', 'format'=>'raw'], [ 'label'=>'Player(s)', 'format' => 'raw', 'value' => function ($dataProvider) { $str = ''; foreach($dataProvider->players as $name) { $str .= ' '; $str .= $name->first.' '; $str .= $name->last.'<br />'; } return nl2br($str); }, 'filter' => function ($dataProvider) { $str = ''; foreach($dataProvider->players as $name) { $str .= ' '; $str .= $name->first.' '; $str .= $name->last.'<br />'; } return nl2br($str); }, ], //'transactionID', // divisionLevel dropdown editable column [ 'class' => 'kartik\grid\EditableColumn', 'header' => 'Division Level', 'attribute' => 'divisionLevelID', 'value' => 'divisionLevelName', 'pageSummary' => true, 'editableOptions'=> function ($model, $key, $index, $widget) { $divisionlevels = ArrayHelper::map(DivisionLevelAssignment::find()->where(['active'=>1])->orderBy('divisionlevelID')->asArray()->all(),'divisionlevelID','exportName'); return [ 'header' => 'Division Level', 'size' => 'sm', 'inputType' => 'dropDownList', 'displayValueConfig' => $divisionlevels, 'data' => $divisionlevels ]; } ], // field dropdown editable column [ 'class' => 'kartik\grid\EditableColumn', 'attribute' => 'field', 'value' => 'fieldName', 'pageSummary' => true, 'editableOptions'=> function ($model, $key, $index, $widget) { $fields = ArrayHelper::map(Fields::find()->all(), 'id','name'); return [ 'header' => 'Field', 'size' => 'sm', 'inputType' => 'dropDownList', 'displayValueConfig' => $fields, 'data' => $fields ]; } ], // editable net column [ 'class'=>'kartik\grid\EditableColumn', 'attribute'=>'net', 'editableOptions'=>[ 'header'=>'Net', 'inputType'=>'textInput', 'options'=>['pluginOptions'=>['min'=>1, 'max'=>60]] ], 'hAlign'=>'right', 'vAlign'=>'middle', 'width'=>'50px' ], // editable team column [ 'class'=>'kartik\grid\EditableColumn', 'attribute'=>'team', 'editableOptions'=>[ 'header'=>'Team #', 'inputType'=>'textInput', 'options'=>['pluginOptions'=>['min'=>1, 'max'=>5]] ], 'hAlign'=>'right', 'vAlign'=>'middle', 'width'=>'50px' ], // 'team', // 'notes:ntext', ['class' => 'yii\grid\ActionColumn'], ], 'storage'=>DynaGrid::TYPE_SESSION, 'theme'=>'panel-danger', 'gridOptions'=>[ 'dataProvider'=>$dataProvider, 'filterModel'=>$searchModel, 'panel'=>['heading'=>'<h3 class="panel-title">Library</h3>'], ], 'options'=>['id'=>'dynagrid-1'] // a unique identifier is important ]); ?> This gives me a column that links to players/index®istrationID=29 My problem here is that I can't seem to get the GridView for Players to filter results so only players with a registrationID = 29 will show up. PlayersController: public function actionIndex() { $searchModel = new PlayersSearch(); if (isset($_GET['registrationID'])) $searchModel->attributes = $_GET['registrationID']; $dataProvider = $searchModel->search(Yii::$app->request->queryParams); return $this->render('index', [ 'searchModel' => $searchModel, 'dataProvider' => $dataProvider, ]); } PlayersSearchModel: public function search($params) { $query = players::find(); // add conditions that should always apply here $dataProvider = new ActiveDataProvider([ 'query' => $query, ]); // setup sorting attributes BEFoRE $this->load($params) $dataProvider->setSort([ 'attributes' =>[ 'ID', 'registrationID', 'fullName' => [ 'asc' => [ 'first' => SORT_ASC, 'last' => SORT_ASC], 'desc' => [ 'first' => SORT_DESC, 'last' => SORT_DESC], 'label' => 'Full Name', 'default' => SORT_ASC ], 'email', 'phone', 'city', 'state', ] ]); if (isset($_GET['PlayersSearch']) && !($this->load($params) && $this->validate())) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); $query->joinWith(['registration']); return $dataProvider; } // grid filtering conditions $query->andFilterWhere(['ID' => $this->ID]); $query->andFilterWhere(['registrationID' => $this->registrationID]); $query->andFilterWhere(['first' => $this->first]); $query->andFilterWhere(['last' => $this->last]); $query->andFilterWhere(['email' => $this->email]); $query->andFilterWhere(['phone' => $this->phone]); $query->andFilterWhere(['city' => $this->city]); $query->andFilterWhere(['state' => $this->state]); $query->andWhere('first LIKE "%' . $this->fullName . '%" ' . 'OR last LIKE "%' . $this->fullName . '%"'); return $dataProvider; }