Does one of the rules in Yii2 map to another model's rules?

Source: Internet
Author: User
The following may be the form data to submit

phpArray ([products] = = Array ([0] = = Array ([product_id] =&gt ; [Product_sku] = 5614546542 [Quantity] = 1 [Price] =&gt ;                    34.00) [1] = = Array ([product_id] = 12                [Product_sku] = 5614546542 [Quantity] = 2 [price] and 34.00 ) [2] = = Array ([product_id] = [product_s        KU] = 5614546542 [Quantity] = 1 [price] + 34.00) ) [Marketing] = = Array ([0] = = Array ([coupon] = 34SDHS                    56aj45dh56 [Provider] = 1) [1] = = Array ( [Coupon] => 33454545324236 [provider] + 2)] [shop_id] = [Member_card] =&G T 3423432423123 [Submittime] = 2015-2-3 9:52:09)

I'm going to write a OrderForm model validation data;
Products correspond to a model, there is also a form validation
Marketing corresponds to a model, which also has form validation

OrderForm's rules should be how to write to achieve products variables corresponding to the rules within the products model;
The marketing variable corresponds to the rules within the marketing model;

Reply content:

The following may be the form data to submit

phpArray ([products] = = Array ([0] = = Array ([product_id] =&gt ; [Product_sku] = 5614546542 [Quantity] = 1 [Price] =&gt ;                    34.00) [1] = = Array ([product_id] = 12                [Product_sku] = 5614546542 [Quantity] = 2 [price] and 34.00 ) [2] = = Array ([product_id] = [product_s        KU] = 5614546542 [Quantity] = 1 [price] + 34.00) ) [Marketing] = = Array ([0] = = Array ([coupon] = 34SDHS                    56aj45dh56 [Provider] = 1) [1] = = Array ( [Coupon] => 33454545324236 [provider] + 2)] [shop_id] = [Member_card] =&G T 3423432423123 [Submittime] = 2015-2-3 9:52:09)

I'm going to write a OrderForm model validation data;
Products correspond to a model, there is also a form validation
Marketing corresponds to a model, which also has form validation

OrderForm's rules should be how to write to achieve products variables corresponding to the rules within the products model;
The marketing variable corresponds to the rules within the marketing model;

Start by creating the model you want, adding ' properties that will save the values submitted by the form and corresponding validation rules/scenarios.
Loads the model into the view, specifying the model for the property when each form item is created, such as:$form->field($marketModel, 'market')->textinput();
Submit the form, and then refer to the steps below to load, verify, save.

Refer to the official documentation for the steps given
1. Instantiate model classes
2. Populate the models attributes with input data
3. Validate All Models
4. If validation passes for all models, save them
5. If validation fails or no data has been submitted, display the form
By passing all model instances to the view

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.