Hi,
I am using yii2 basic. I have a groupdetails table and CRUD.
I have groupsavingdetails table. One group has many group saving details.
Groupdetails - Table
- GroupId
- GroupName
Groupsavingdetails - Table
- GroupsavingdetailsId
- GrroupId
- Year
In the model of Groupsavingdetails, for Year field I have a rule which validates the year. The entered year must be greater than or = to the year in Date of Formation of the group selected. I have a method as below.
public function validateyear($attribute,$params,$validator)
{
$group = Groupdetails::find()->where(['GroupId' => $this->GroupId])->all();
$year;
if ($group !=null) {
foreach($group as $groups)
{
$year= $groups['FormationDate'];
}
$year1= explode('-', $year);
if($this->attribute<$year1[0])
$this->addError($attribute,'Year should be greater than or = to '.$year1[0]);
}
else
{
$this->addError($attribute,'Such group not there');
}
}
Here if the Date of Formation is 2017-08-08, and the year entered by user is 2016, still the error message is not shown.
How to resolve error?