title: How to put begin-commit transaction in controller: cakephp?
body: <p>I'm working on a controller that will update a few tables. I am able to call my model from my controller and inside the model function I can make a begin and commit my query, it can rollback should an error happen.</p>
  
  <p>Here is my sample:</p>
  
  <p>Controller:</p>
  
  <pre><code>//update table when update button is clicked
      if (!empty($this-&gt;data)) {
          if ($this-&gt;Item-&gt;update($this-&gt;data)) {
              $this-&gt;Item-&gt;create();
              $this-&gt;redirect('/sample');
              return;
          } else {
              $this-&gt;set('data', $this-&gt;data);
          }
      }
  </code></pre>
  
  <p>Model:</p>
  
  <pre><code>function update($data)
  {
      $this-&gt;begin($this);
      if(!parent::save($data)) {
          $this-&gt;rollback($this);
          return false;
      }
  
      $this-&gt;commit();
      return true;
  }
  </code></pre>
  
  <p>Now this works fine. But what I need to do is to call another model in my controller like "$this->"ANOTHER MODEL HERE"->update()". I need to have rollback should a problem occur with either model transaction. What I'm thinking is to put a commit in my controller after both model call succeeds. </p>
  
  <p>Much like this:</p>
  
  <pre><code>CONTROLLER PHP:
    BEGIN TRANSACTION
      -&gt;CALLS MODEL1
          IF(MODEL1 == ERROR){
               ROLLBACK
          }
      -&gt;CALLS MODEL2
          IF(MODEL2 == ERROR){
               ROLLBACK
          }
     COMMIT WHEN NO PROBLEM IS ENCOUNTERED
  </code></pre>
  
  <p>So is it possible to perform commit in controller? I am only able to do it in model. Thanks in advance!</p>