Рядом в div выводятся результаты поиска SearchForm, каждая карточка сотрудника должна по ссылке в имени и фамилии вести на страницу, где по середине отображается детальная информация карточки(DetailView), справа - уменьшенный блок с результатами поиска. Блок с селектами должен оставаться на месте. Соответственно вопрос, как сделать это всё, да ещё без перезагрузки страницы.
indexView:
Код: Выделить всё
<?php
use yii\helpers\Html;
use yii\widgets\ListView;
use yii\widgets\Pjax;
use yii\helpers\ArrayHelper;
/* @var $this yii\web\View */
/* @var $searchModel app\models\UserSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
/**$this->title = 'Select Forms';
$this->params['breadcrumbs'][] = $this->title;**/
?>
<div class="select-form-index">
<h1><?php // echo Html::encode($this->title) ?></h1>
<?php echo $this->render('_search', ['model' => $searchModel]); ?>
<?php Pjax::begin(); ?>
<div class="details">
</div>
<div style="display: inline-block;vertical-align: top;">
<?= ListView::widget([
'dataProvider' => $dataProvider,
'itemOptions' => ['class' => 'item'],
'itemView' => function ($model, $key, $index, $widget){
$defaultAva = '@web/ava/no_img.jpg';
$avatar = /**'@web/ava/' . **/Html::img( $model->avatar ? $model->avatar : $defaultAva, ['alt' => 'Фотография пользователя']);
/**$avatar = ArrayHelper::getValue($model, function ($model, $defaultAva) {
return Html::img($model->avatar, ['alt' => 'Фотография пользователя']);
});**/
$userCard = ArrayHelper::getValue($model, function ($model, $defaultValue) {
return Html::encode($model->name . ' ' . $model->surname);
});
return $avatar . ' ' . Html::tag('p', Html::a(Html::encode($userCard), ['view', 'id' => $model->id]), ['class' => 'cardUsername']) . Html::tag('p', Html::a(Html::encode($model->position), ['view', 'position' => '&UserSearch%5Bsubdivision%5D=$model->position']), ['class' => 'cardSubdivision']) . Html::tag('p', Html::a(Html::encode($model->subdivision), ['view', 'subdivision' => '&UserSearch%5Bsubdivision%5D=$model->subdivision']), ['class' => 'cardSubdivision']);
}
]); ?>
</div>
<div class="mini_cards">
</div>
<?php Pjax::end(); ?>
<!--<p>
<?= Html::a('Create Select Form', ['create'], ['class' => 'btn btn-success']) ?>
</p>-->
</div>
Код: Выделить всё
<?php
namespace app\controllers;
use Yii;
use app\models\SelectForm;
use app\models\UserSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
/**
* AdminController implements the CRUD actions for SelectForm model.
*/
class AdminController extends Controller
{
/**
* @inheritdoc
*/
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['POST'],
],
],
];
}
/**
* Lists all SelectForm models.
* @return mixed
*/
public function actionIndex()
{
$searchModel = new UserSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
/**
* Displays a single SelectForm model.
* @param integer $id
* @return mixed
*/
public function actionView($id)
{
return $this->render('view', [
'model' => $this->findModel($id),
]);
}
/**
* Creates a new SelectForm model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new SelectForm();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', [
'model' => $model,
]);
}
}
/**
* Updates an existing SelectForm model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @return mixed
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('update', [
'model' => $model,
]);
}
}
/**
* Deletes an existing SelectForm model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id
* @return mixed
*/
public function actionDelete($id)
{
$this->findModel($id)->delete();
return $this->redirect(['index']);
}
/**
* Finds the SelectForm model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return SelectForm the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = SelectForm::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
}
Код: Выделить всё
<?php
use yii\helpers\Html;
use yii\widgets\DetailView;
use yii\widgets\ListView;
/* @var $this yii\web\View */
/* @var $model app\models\SelectForm */
$this->title = $model->name .' ' . $model->surname;
$this->params['breadcrumbs'][] = ['label' => 'Select Forms', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="select-form-view">
<h1><?php // echo Html::encode($this->title) ?></h1>
<p>
<?= Html::a('Update', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
<?= Html::a('Delete', ['delete', 'id' => $model->id], [
'class' => 'btn btn-danger',
'data' => [
'confirm' => 'Are you sure you want to delete this item?',
'method' => 'post',
],
]) ?>
</p>
<?= DetailView::widget([
'model' => $model,
'attributes' => [
'avatar:image',
'name',
'surname',
'middlename',
'sex',
'birth_date',
'city',
'position',
'subdivision',
],
]) ?>
</div>
Код: Выделить всё
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use app\models\User;
/* @var $this yii\web\View */
/* @var $model app\models\UserSearch */
/* @var $form yii\widgets\ActiveForm */
?>
<div class="select-form-search">
<?php $form = ActiveForm::begin([
'action' => ['index'],
'method' => 'get',
]); ?>
<?php // echo $form->field($model, 'id') ?>
<?= $form->field($model, 'name') ?>
<?= $form->field($model, 'surname') ?>
<?php // echo$form->field($model, 'middlename') ?>
<?php // echo$form->field($model, 'sex') ?>
<?php // echo $form->field($model, 'birth_date') ?>
<?= $form->field($model, 'city')->dropdownList(User::find()->select(['city', 'id'])->indexBy('city')->column(), ['prompt'=>'Город']); ?>
<?= $form->field($model, 'position')->dropdownList(User::find()->select(['position', 'id'])->indexBy('position')->column(), ['prompt'=>'Должность']); ?>
<?= $form->field($model, 'subdivision')->dropdownList(User::find()->select(['subdivision', 'id'])->indexBy('subdivision')->column(), ['prompt'=>'Подразделение']); ?>
<?php // echo $form->field($model, 'avatar') ?>
<div class="form-group">
<?= Html::submitButton('Search', ['class' => 'btn btn-primary']) ?>
<?= Html::resetButton('Reset', ['class' => 'btn btn-default']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>