Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class A extends yiidbActiveRecord
- {
- public $category;
- public function rules()
- {
- return [
- [['category'], 'safe'],
- ];
- }
- }
- {
- public $item;
- public $category;
- public function rules()
- {
- return [
- [['item'], 'safe'],
- [['item'], 'required', 'when' => function($model) {
- return $model->category == 'yes';
- }]
- ];
- }
- }
- $a = new A();
- $b = new B();
- if ($a->load(Yii::$app->request->post()) && $b->load(Yii::$app->request->post())) {
- $b->category= Yii::$app->request->post()['First']['category'];
- $isValid = $a->validate();
- $isValid = $b->validate() && $isValid;
- if ($isValid) {
- echo 'its valid';
- }
- }
Add Comment
Please, Sign In to add comment