• <bdo id='FPxZQ'></bdo><ul id='FPxZQ'></ul>

        <i id='FPxZQ'><tr id='FPxZQ'><dt id='FPxZQ'><q id='FPxZQ'><span id='FPxZQ'><b id='FPxZQ'><form id='FPxZQ'><ins id='FPxZQ'></ins><ul id='FPxZQ'></ul><sub id='FPxZQ'></sub></form><legend id='FPxZQ'></legend><bdo id='FPxZQ'><pre id='FPxZQ'><center id='FPxZQ'></center></pre></bdo></b><th id='FPxZQ'></th></span></q></dt></tr></i><div id='FPxZQ'><tfoot id='FPxZQ'></tfoot><dl id='FPxZQ'><fieldset id='FPxZQ'></fieldset></dl></div>

      1. <small id='FPxZQ'></small><noframes id='FPxZQ'>

        <tfoot id='FPxZQ'></tfoot>

        <legend id='FPxZQ'><style id='FPxZQ'><dir id='FPxZQ'><q id='FPxZQ'></q></dir></style></legend>
      2. yii 中验证规则的场景

        scenario for validation rules in yii(yii 中验证规则的场景)
          <i id='q2Fsc'><tr id='q2Fsc'><dt id='q2Fsc'><q id='q2Fsc'><span id='q2Fsc'><b id='q2Fsc'><form id='q2Fsc'><ins id='q2Fsc'></ins><ul id='q2Fsc'></ul><sub id='q2Fsc'></sub></form><legend id='q2Fsc'></legend><bdo id='q2Fsc'><pre id='q2Fsc'><center id='q2Fsc'></center></pre></bdo></b><th id='q2Fsc'></th></span></q></dt></tr></i><div id='q2Fsc'><tfoot id='q2Fsc'></tfoot><dl id='q2Fsc'><fieldset id='q2Fsc'></fieldset></dl></div>

              <tbody id='q2Fsc'></tbody>

            <tfoot id='q2Fsc'></tfoot>

              <small id='q2Fsc'></small><noframes id='q2Fsc'>

                <legend id='q2Fsc'><style id='q2Fsc'><dir id='q2Fsc'><q id='q2Fsc'></q></dir></style></legend>
                • <bdo id='q2Fsc'></bdo><ul id='q2Fsc'></ul>
                  本文介绍了yii 中验证规则的场景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在徘徊有没有机会用场景做规则,

                  I was wandering is there any chance to use scenario for rules,

                  在我的模型中我有

                  public function rules()
                  {
                      return array(
                          array('delivery, firstNameBilling, lastNameBilling, addressBilling, cityBilling, countryBilling,
                              postBilling, telephoneBilling, mailBilling, firstNameDelivery, lastNameDelivery, addressDelivery,
                              cityDelivery, countryDelivery, postDelivery, telephoneDelivery, mailDelivery', 'required'),
                          array('active', 'numerical', 'integerOnly'=>true),
                      );
                  }
                  

                  在我看来我有这样的事情

                  and in my view I have something like this

                      <tr>
                          <td>
                              <p><?php echo $form->label($model,'telephoneBilling'); ?><span>:&nbsp;</span><span class="required">*</span></p>
                          </td>
                          <td>
                              <?php echo $form->textField($model,'telephoneBilling'); ?>
                              <?php echo $form->error($model,'telephoneBilling'); ?>
                          </td>
                      </tr>
                  </table>
                  
                  <p><?php echo $form->checkBox($model,'active', array('class' => 'change')); ?>
                      Delivery information: Please check the box if your delivery address differs from your billing address and enter the
                      required delivery address in the fields provided below.</p>
                  
                      <div id="deliveryFormWrapper" style="display: none">
                      <table class="cartReviewTable">
                      <tr>
                          <td colspan="4">
                              <span class="blueTitle"><?php echo CHtml::encode(Yii::t('app', 'Delivery Information ')); ?></span>
                          </td>
                      </tr>
                      <tr>
                          <td>
                              <p><?php echo $form->label($model,'firstNameDelivery'); ?><span>:&nbsp;</span><span class="required">*</span></p>
                          </td>
                          <td>
                              <?php echo $form->textField($model,'firstNameDelivery'); ?>
                              <?php echo $form->error($model,'firstNameDelivery'); ?>
                          </td>
                  

                  这只是给你一张我所做的图片的一部分,所以当我点击复选框时,我会显示这个隐藏的 div,他的字段有一个规则(第一个 div 包含账单字段,隐藏的包含交付字段.

                  This is just a part to give you a picture what i do, so when i click on checkbox i show this hidden div, and he has a rules for his fields (the first div contains Billing fields, and the hidden contains delivery fields.

                  当我想提交表单而复选框没有被选中时,我不能这样做,因为必填字段,所以我在徘徊有没有机会在那种情况下使用场景以及如何使用,我需要一个线索.

                  When i want to submit the form and the checkbox is not selected, i cant do it, because of required fields, so i was wandering Is there any chance to use scenario for that situation and how, i need a clue.

                  谢谢,我希望你能理解我的问题.

                  Thanks, i hope you can understand my question.

                  推荐答案

                  是的,这是可能的.在您的控制器中,您可以检查复选框是否已选中,然后设置方案.类似的东西

                  Yes its possible. In your controller you can check if checkbox checked or no, then set scenario. Something like that

                    if($_POST['my_checbox']==1)
                     $model->setscenario('checked');  
                  

                  然后只需执行 $model->validate() 来检查错误.在您的模型规则中,只需为您拥有的场景设置验证器:

                  Then just do $model->validate() to check for errors. In your model rules just set validators for scenarios you have:

                  array('delivery, firstNameBilling, lastNameBilling, addressBilling, cityBilling, countryBilling,
                              postBilling, telephoneBilling, mailBilling, firstNameDelivery, lastNameDelivery, addressDelivery,
                              cityDelivery, countryDelivery, postDelivery, telephoneDelivery, mailDelivery', 'required','on'=>'checked'),
                  

                  仅此而已.很简单.

                  这篇关于yii 中验证规则的场景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Is PHP or PHP based web framework stateful or stateless?(PHP 或基于 PHP 的 Web 框架是有状态的还是无状态的?)
                  How to parse django style template tags(如何解析 django 样式模板标签)
                  What is a good setup for editing PHP in Emacs?(在 Emacs 中编辑 PHP 的好设置是什么?)
                  How to check whether specified PID is currently running without invoking ps from PHP?(如何在不从 PHP 调用 ps 的情况下检查指定的 PID 当前是否正在运行?)
                  What#39;s the difference between escapeshellarg and escapeshellcmd?(escapeshellarg 和escapeshellcmd 有什么区别?)
                  php in background exec() function(php 后台 exec() 函数)

                          <bdo id='aO5p8'></bdo><ul id='aO5p8'></ul>
                        • <legend id='aO5p8'><style id='aO5p8'><dir id='aO5p8'><q id='aO5p8'></q></dir></style></legend>
                        • <tfoot id='aO5p8'></tfoot>
                            <tbody id='aO5p8'></tbody>

                            <small id='aO5p8'></small><noframes id='aO5p8'>

                            <i id='aO5p8'><tr id='aO5p8'><dt id='aO5p8'><q id='aO5p8'><span id='aO5p8'><b id='aO5p8'><form id='aO5p8'><ins id='aO5p8'></ins><ul id='aO5p8'></ul><sub id='aO5p8'></sub></form><legend id='aO5p8'></legend><bdo id='aO5p8'><pre id='aO5p8'><center id='aO5p8'></center></pre></bdo></b><th id='aO5p8'></th></span></q></dt></tr></i><div id='aO5p8'><tfoot id='aO5p8'></tfoot><dl id='aO5p8'><fieldset id='aO5p8'></fieldset></dl></div>