0

Как сделать собственное view в для searchModel? Не gridView, а собрать самому. Мучаюсь сутки! Вот модель:

<?php

namespace backend\models\search;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\Truck;

/**
 * ArticleSearch represents the model behind the search form about `common\models\Article`.
 */
class TruckSearch extends Truck
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['id'], 'integer'],
            [['id', 'type_id', 'name', 'carrying'], 'safe'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = Truck::find();

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        if (!($this->load($params) && $this->validate())) {
            return $dataProvider;
        }

        $query->andFilterWhere([
            'id' => $this->id,
            'type_id' => $this->type_id,
            'name' => $this->name,
            'carrying' => $this->carrying,
            'status' => $this->status,
        ]);

        /*$query->andFilterWhere(['like', 'slug', $this->slug])
            ->andFilterWhere(['like', 'title', $this->title])
            ->andFilterWhere(['like', 'body', $this->body]);*/

        return $dataProvider;
    }
}

1 ответ 1

0

Вы можете в контроллере вызвать конструкцию вида: return $this->render('/custom-truck', ['myTruck' => $truck]);. При этом контроллер попытается обработать файл по адресу .../views/custom-truck.php, в этом файле вам будет доступна переменная $myTruck в которой будет содержаться переданная вами переменная truck. Дальше вы можете делать с ней что хотите.

Подробнее о создании view вы можете прочитать в официальной документации.

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.