I have problem with my sqldataprovider starting count from 0 which creates troubles accesing the correct data later in Gridview. Dataprovider work fine, though i need to retrieve data from 2 tables under a new name and its easier for me to do such thing with good old sql.
My dataProvider code
$count = (int)Towar::find()->count();
$dataProvider = new SqlDataProvider([
'sql' => 'SELECT towar.nazwa,cena,dostep,promo,producent,kategorie.nazwa as kategoria FROM towar,kategorie WHERE `id_kat`=kategorie.id',
'totalCount' => $count,
'pagination' => [
'pageSize' => 40,
],
]);
The yii2 grid with ActiveDataProvider approach is that you define the relationships between the models inside the models themselves so you don’t have to write join queries as you have done. In the gridview you can just have direct access to the related models.
eg in your gridview widget you can do something like
Emm and how the DataProvider should look in this case ? if I use Towar::find() it wont allow me to retrieve attribute from Kategorie and it seems perfectly logical.
All i want is to retrieve every record from Towar and display it in gridview using corresponding names from Kategorie . Queries i written does this perfectly only with this 1 small issue that they generate links in gridview that starts with id=0 instead of id=1. My models are gii generated and have 1:1 relation defined on Towar.id_kat=Kategorie.id
//why this forum thinks it is a spam when i quote your post oO