I am using yii2 basic application template. I have employee CRUD, and Church CRUD. In my application church is master table which stores church details. The scenario is that I have to assign employee as pastors to churches. So I have a table churchassignment which has foll fields:
Table: churchassignment
- ChurchAssignmentId
- ChurchId
- EmployeeId
Here in above table ChurchId is forign key coming from Church master table and EmployeeId is also foreign key coming from Employee table.
The table structure for church master table is as below:
Table : Church
- ChurchId
- Church
- CommunityType
- District Id
- TalukaId
- VillageId
- LocationId
- AreaId
Basically the above structure shows that if community type is rural then LoctionId and AreaId will be Null and if CommunityType is Urban then DistrictId, TalukaId and VillageId will be set to Null.
I have CRUD for church assignments as well.
Now I want that while creating church assignments, I want to show churches in drop down as follows for example:
LWF-Aurangabad-Paithan-Khadgaon
Here LWF is the name of church, Aurangabad is District, Paithan is Taluka and Khadgaon is village.
So in Church models I have foll function:
public function getChurch()
{
$churchdetails = Yii::$app->db->createCommand('SELECT church.ChurchName, district.District, taluka.Taluka,village.Village
FROM church, district, taluka, village
where church.DistrictId=district.DistrictId AND
church.TalukaId=taluka.TalukaId AND
church.VillageId=village.VillageId')->queryAll();
foreach($churchdetails as $churchdetails1)
{
return $churchdetails1['ChurchName'] . '-' . $churchdetails1['District'].'- '.$churchdetails1['Taluka'].'-'.$churchdetails1['Village'];
}
}
And in Churchassignments CRUD, I have foll code for selecting the church:
<?= $form->field($model, 'ChurchId')->dropDownList(ArrayHelper::map(Church::find()->all(),'ChurchId','church'), ['prompt' => 'Select Church']) ?>
But when I run the code, I see only first record from church master table is displayed 3 times.
How to accomplish this?