Guest User

Untitled

a guest
Apr 25th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. class A extends yiidbActiveRecord
  2. {
  3. public $category;
  4.  
  5. public function rules()
  6. {
  7. return [
  8. [['category'], 'safe'],
  9. ];
  10. }
  11.  
  12.  
  13.  
  14. }
  15.  
  16. {
  17. public $item;
  18. public $category;
  19.  
  20. public function rules()
  21. {
  22. return [
  23. [['item'], 'safe'],
  24. [['item'], 'required', 'when' => function($model) {
  25. return $model->category == 'yes';
  26. }]
  27. ];
  28. }
  29. }
  30.  
  31. $a = new A();
  32. $b = new B();
  33. if ($a->load(Yii::$app->request->post()) && $b->load(Yii::$app->request->post())) {
  34. $b->category= Yii::$app->request->post()['First']['category'];
  35.  
  36. $isValid = $a->validate();
  37. $isValid = $b->validate() && $isValid;
  38. if ($isValid) {
  39. echo 'its valid';
  40. }
  41.  
  42.  
  43. }
Add Comment
Please, Sign In to add comment