my question is, where is the best way to build a grid with a data join from two table?
Now. I do this.
i create the crud with gii.
i perform the query with join by sql
this is my search model
public function search($params)
{
//$query = AgenzieIndirizzo::find();
$sql = 'SELECT * FROM agenzie_indirizzo LEFT JOIN agenzie_main ON agenzie_indirizzo.id_agenzia = agenzie_main.id';
$query = AgenzieIndirizzo::findBySql($sql);
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
if (!($this->load($params) && $this->validate())) {
return $dataProvider;
}
$this->addCondition($query, 'agenzie_main.name');
$this->addCondition($query, 'id');
$this->addCondition($query, 'id_agenzia');
$this->addCondition($query, 'nome', true);
$this->addCondition($query, 'tipo_ind');
$this->addCondition($query, 'citta', true);
$this->addCondition($query, 'provincia', true);
$this->addCondition($query, 'tipo_via');
$this->addCondition($query, 'via', true);
$this->addCondition($query, 'numero_civ', true);
$this->addCondition($query, 'cap', true);
$this->addCondition($query, 'user_ins');
$this->addCondition($query, 'data_ins');
$this->addCondition($query, 'user_mod');
$this->addCondition($query, 'data_mod');
$this->addCondition($query, 'name');
return $dataProvider;
}
after i declare the filed as var in the main model.
i think this work but is not the right method.
( how display in the grid a field if two table has same name filed ex. ‘id’ … i try db.it … and other)
anyone can help me?