public function actionIndex()
{
$searchModel = new ZakazSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
$seatchPhone = Yii::$app->request->get('PhoneSearch');
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
'seatchPhone' => $seatchPhone,
]);
}
$user = Zakaz::findOne('id_sotrud');
$user = $user->name;
DetailView::widget([
[
'attribute' => 'id_sotrud', // а тут что Вы ожидаете увидеть?
// данные реляции? так Вы ж их не выводите
'value' => $user,
],
])
[
'attribute' => 'id_tovar',
'value' => 'idTovar.name',
'filter' => Zakaz::getTovarList(),
],
<?php
namespace app\models;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use app\models\Zakaz;
/**
* ZakazSearch represents the model behind the search form about `app\models\Zakaz`.
*/
class ZakazSearch extends Zakaz
{
/**
* @inheritdoc
*/
public function rules()
{
return [
[['id_zakaz', 'id_sotrud', 'id_tovar', 'oplata', 'number', 'phone'], 'integer'],
[['srok', 'minut', 'prioritet', 'status', 'data', 'name', 'email'], 'safe'],
];
}
/**
* @inheritdoc
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = Zakaz::find();
// add conditions that should always apply here
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
// grid filtering conditions
$query->andFilterWhere([
'id_zakaz' => $this->id_zakaz,
'srok' => $this->srok,
'id_sotrud' => $this->id_sotrud,
'id_tovar' => $this->id_tovar,
'oplata' => $this->oplata,
// 'number' => $this->number,
'data' => $this->data,
'name' => $this->name,
'phone' => $this->phone,
'email' => $this->email
]);
$query->andFilterWhere(['like', 'prioritet', $this->prioritet])
->andFilterWhere(['like', 'status', $this->status])
->andFilterWhere(['like', 'name', $this->name])
->andFilterWhere(['like', 'phone', $this->phone])
->andFilterWhere(['like', 'email', $this->email]);
// ->andFilterWhere(['like', 'description', $this->description])
// ->andFilterWhere(['like', 'information', $this->information])
// ->andFilterWhere(['like', 'comment', $this->comment]);
return $dataProvider;
}
public function attributeLabels()
{
return [];
}
}
['id_sotrud', 'default', 'value'=>Yii::$app->user->id],
вот так работает с user-ом public function rules()
{
return [
[['srok', 'minut', 'id_sotrud', 'oplata', 'number', 'data', 'description','name', 'phone'], 'required'],
[['id_zakaz', 'id_sotrud', 'id_tovar', 'oplata', 'number'], 'integer'],
[['srok', 'minut', 'data'], 'safe'],
[['comment'], 'string'],
['status' , 'default', 'value'=>'Новый'],
[['prioritet', 'status'], 'string', 'max' => 36],
[['description', 'information'], 'string', 'max' => 500],
[['img', 'email'],'string', 'max' => 50],
[['id_sotrud'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['id_sotrud' => 'id']],
[['id_tovar'], 'exist', 'skipOnError' => true, 'targetClass' => Tovar::className(), 'targetAttribute' => ['id_tovar' => 'id']],
];
}