Hello,
I try to code an application in Yii2 and don’t know how to call the “default search” method generated by Gii to filter data.
Concrete:
I have a table A (liedblock) with (id, title, …) and a table B (liedblocklieder) with (id, liedblock_id, …).
There is an foreign key relation between A and B with A.id->B.liedblock_id.
Gii generated all Controller, Models and "SearchModels".
In my Liedblock.index-View I want to insert a link to the LiedblockliederController.index-Action using the foreigkey "liedblock_id".
liedblock/index.php (GrieView)
[
'attribute' => 'title',
'format' => 'raw',
'value' => function ($data) {
return Html::a($data->title, ['liedblock-lieder/view', 'id'=> 0, 'liedblock_id' => $data->id]);
},
'contentOptions' => ['style' => 'width:20px;'] // <-- right here
],
As result I expect to get all results from table B (liedblocklieder) wich match the given lieblocklieder_id.
models/LiedblockLiederSearch.php
public function search($params) {
$query = LiedblockLieder::find();
$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;
}
$query->andFilterWhere([
'id' => $this->id,
'lied_id' => $this->lied_id,
'liedblock_id' => $this->liedblock_id,
'position' => $this->position,
'create_time' => $this->create_time,
'update_time' => $this->update_time,
]);
$query->andFilterWhere(['like', 'bemerkung', $this->bemerkung]);
return $dataProvider;
}
Can somebody help me to create the correct link to fill in the attributes for the search() method please?
Thx