title: Create a dynamic conditional validation in Cakephp
body: <p>I want to set these validation rule in CakePHP</p>
  
  <p><strong>Rule:</strong></p>
  
  <p>One of these fields is required but not both.</p>
  
  <pre><code>discount_percent
  discount_amount
  </code></pre>
  
  <p>If discount_amount is input as 0 a NULL should be saved and then discount_percent is required to be > 1 but &lt;=100.</p>
  
  <p>If discount_percent is input a 0 then a NULL should be saved and then discount_amount is required to be > 0 but &lt;= products.price for the selected product.</p>
  
  <p>I have tried but not getting right way to perform this validation.</p>
  
  <p><strong>Modal Code:</strong> </p>
  
  <pre><code>App::uses('AppModel', 'Model');
  
  class Code extends AppModel {
  
      public $validate = array(
  
          'discount_amount' =&gt; array(
              'rule' =&gt; array('checkLimit'),
              'message' =&gt; 'Please supply a valid discount_amount'
          ),
          'discount_percent' =&gt; array(
              'rule' =&gt; array('checkLimit'),
              'message' =&gt; 'Please supply a valid discount_percent'
          )
      );
  
      public function checkLimit($field) {
          $passed = true;
  
          if (isset($this-&gt;data[$this-&gt;alias]['discount_amount']) &amp;&amp; empty($this-&gt;data[$this-&gt;alias]['discount_amount'])) {
  
              ??????
  
          } else {
  
              ??????
          }
      }
  
  }
  </code></pre>