Hello Guys,
is it possible to display a static variable from a class as a field (ActiveForm) in the view?
I have a class class CCrossSelling extends ActiveRecord.
class CCrossSelling extends ActiveRecord{
public $isUsed;
public $cCrossSellingContainers;
....
}
This class contains a variable
public $cCrossSellingContainers;
which holds a list of objects from the class CCrossSellingContainer extends ActiveRecord.
In CCrossSelling there is also a variable called public $isUsed;.
Now I want to disable the rules of all existing CrossSellingContainers if isUsed == true.
My rules in CCrossSellingContainer:
public function rules()
{
return [
[['title', 'price'], 'required'],
[['price'], 'number', 'numberPattern' => '/^\s*[-+]?[0-9]*[.,]?[0-9]+([eE][-+]?[0-9]+)?\s*$/'],
['description', 'safe'],
];
}
I need somethin like this:
return [
[..., 'required', 'when' => function ($model) { $model->isUsed == true; }, 'whenClient' => "isNewsletterComponentUsed"],
];
But I cant check directly on isUsed in this case, because it’s stored in the CCrossSelling object and not in the CCrossSellingContainer.
Is there any way to disable the rules in the given case? Thanks alot!