title: Yii - generating a URL while preserving or deleting GET parameters
body: <p>I currently have a view, manage, that lists data items. Instead of running "edit" and "add" actions with separate views, I'm having the appropriate form display inline in the page when it is needed. On the form is a "cancel" button that will hide it.</p>
  
  <p>Right now I decide what, if any, form to display inline through a GET parameter called <code>mode</code>. So <code>/controller/manage</code> will display the items, while <code>/controller/manage?mode=edit</code> will display the items and show the edit form for the correct data item.</p>
  
  <p>The action accepts various other GET parameters such as a date interval.</p>
  
  <p>In order to activate the form, I'm generating a link to the current action with the <code>mode</code> parameter spliced in with existing parameters in <code>$_GET</code>. I'm using the following one-liner:</p>
  
  <pre><code>&lt;?php echo CHtml::link('Edit', array_merge(array('/session/manage', 'mode' =&gt; 'edit', 'id' =&gt; 6), $_GET)); ?&gt;
  </code></pre>
  
  <p>To implement the "cancel" link, I'm using:</p>
  
  <pre><code>&lt;?php echo CHtml::link('Cancel', array_diff(array_merge(array('/session/manage'), $_GET), array('edit'))); ?&gt;
  </code></pre>
  
  <p>My question is: is there a cleaner way to do this? While this <em>works</em>, it feels like a hack. I haven't found any documentation on generating URLs that include existing GET parameters. Does Yii provide a built-in method to do what I want to do? Should I re-evaluate my general approach to conditional views, which might in turn yield a cleaner solution?</p>