I want to organize a search without using Gridview and display the search results in an array. There is a table with such fields as id ... from, to, and others. It is necessary to organize a search in 2 fields, so if the entered data from both fields (from and to) of one table is in the database, output them in an array.
Search does not work yet. After clicking on the search page is updated and remains on site / index (without displaying any result) I do not know why please help who can. I really want the search to work
code from siteController.php
public function actionSearch() { $driver = new Driver(); if ($driver->load(Yii::$app->request->post())) { $driver = Driver::find() ->where(['from' => $driver->from]) ->andWhere(['to' => $driver->to]) ->one(); return $this->render('search', ['driver' => $driver]); } else { throw new NotFoundHttpException('Input data not found' ); } } code from models / Driver.php
<?php namespace app\models; use yii\base\Model; use yii\data\ActiveDataProvider; use Yii; /** * This is the model class for table "driver". * * @property string $id * @property string $from * @property string $to * @property string $data * @property string $about * @property string $car */ class Driver extends \yii\db\ActiveRecord{ /** * @inheritdoc */ public static function tableName() { return 'driver'; } /** * @inheritdoc */ public function rules() { return [ // [['from', 'to', 'data', 'about', 'car'], 'required'], [['about'], 'string'], [['from', 'to', 'data', 'car'], 'string', 'max' => 255], ]; } /** * @inheritdoc */ public function attributeLabels() { return [ 'id' => 'ID', 'from' => 'From', 'to' => 'To', 'data' => 'Data', 'about' => 'About', 'car' => 'Car', ]; } } code from site / index.php
<?php use yii\widgets\ActiveForm; use yii\helpers\Html; use app\models\Driver; /* @var $driver app\models\Driver */ ?> <?php $driver = new Driver; ?> <div class="row"> <div> <?php $form = ActiveForm::begin(); ?> <div class="row"> <div class="col-xs-5"> <?= $form->field($driver, 'from')->label('От')->textInput(['class' => 'input form-control']) ?> </div> <div class="col-xs-5"> <?= $form->field($driver, 'to')->label('До')->textInput(['class' => 'input form-control']) ?> </div> <div class="col-xs-2" align="left" style="margin-top: 30px"> <input type="image" src="<?= \Yii::getAlias('@web/images/button_search.png')?>" class="icon_button" alt="Поиск" > </div> </div> <?php ActiveForm::end(); ?> </div> </div> code from site / search.php
<?php use yii\widgets\LinkPager; $this->title = "Поиск"; $this->registerMetaTag([ 'name' => 'description', 'content' => 'driver', ]); $this->registerMetaTag([ 'name' => 'keywords', 'content' => 'driver', ]) ?> <?php ?> <?php if (!$driver) { ?> <p>Ничего не найдено</p> <?php } else { ?> <?php foreach ($driver as $one){ $from = $one -> from; $to = $one -> to; $data = $one -> data; ?> <div class="one"> <table> <tr> <td> <p><?=$from?></p> </td> <td class="right"> </td> <td class="center"> <p><?=$to?></p> </td> </tr> </table> <div class=""> <?=$data?> <br> <div class="clear"></div> </div> </div> <?php }?> <?php } ?> and site / found_drivers.php it is now empty