title: Using transaction in a loop in Yii
body: <p>I have an array of active records and want to change some field of them with a loop in this manner:  </p>
  
  <pre><code>$error = false;
  foreach ($items as $item) {
      $item-&gt;is_paid = self::PENDING;
      $error = $error || !$item-&gt;save();
  }
  return $error;
  </code></pre>
  
  <p>What I want to do is to change the <code>is_paid</code> property for all of this items. If on fails, roll back the others. How can I use transaction to solve this problem?</p>