Hi, i’m trying to create a count which shows the amount of Platforms within a country,
my Db tables are set up like this
I have a Country Table with -> country_id and country_name,
and a Platform table with -> platform_id, platform_name and platform_country_id,
i want to show the Amount of Platforms in each country in a Gridview, this is what i have so far,
CountriesController
<?php
use backend\models\Platforms;
//some Code...
public function actionIndex()
{
$searchModel = new CountriesSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
$country_id = $searchModel->country_id;
$platformsCount = Platforms::find()
->select(['COUNT(*)'])
->where('platform_country_id = :country_id', [':country_id' => $country_id])
->all();
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
'platformCount' => $platformsCount,
]);
}
and this is my View index atm.
countries index
<?php
//some code...
<?php Pjax::begin(); ?>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
// A few Attributes from countries...
[
'value' => function ($platformCount){
if(isset($platformCount)){
return $platformCount 'in this country';
}
else {
return 'No platforms in Country';
}
},
'label' => 'Amount of Platforms',
],
//More in the view
but it throws me a "htmlspecialchars() expects parameter 1 to be string, object given" error.
I know that i have 2 platforms in a country and 1 other in another country.
am i doing anything wrong? or missing something? this is as far as i could get with the use of the internet.
Thanks in advance