title: CakePHP passing id to edit form
body: <p>I've noticed that their is many different ways to pass an ID to a form when editing a database entry. So for example for a edit user profile form I have the following code:</p>
  
  <pre><code>function edit($id = null)
  {
      $this-&gt;layout = 'page';
  
      // this line isn't needed?
      //$this-&gt;User-&gt;id = $id;
  
      if (empty($this-&gt;data))
      {
          $this-&gt;data = $this-&gt;User-&gt;read();
      }
      else
      {
          if ($this-&gt;User-&gt;save($this-&gt;data))
          {
              $this-&gt;Session-&gt;setFlash('Your profile has been updated', 'flash', array('header' =&gt; 'Announcement', 'myclass' =&gt; 'success'));
              $this-&gt;redirect(array('controller' =&gt; 'users', 'action' =&gt; 'view', $id));
          }
      }
  }
  </code></pre>
  
  <p>Now the function expects an id passing in the url e.g. <code>/users/edit/2</code> But let's say I wanted it to be something more user friendly like <code>/profile/edit</code> (rewrote by routing) I would no longer be passing in the ID as part of the url. As you can see in my code I have a line I have commented out because it isn't needed?</p>
  
  <p>Also in the form I ALSO Need <code>&lt;?php echo $this-&gt;Form-&gt;input('id', array('type' =&gt; 'hidden')); ?&gt;</code> why?</p>
  
  <p>Basically this is more of what are the options available to me to build various types of edit forms and passing data to the form. And what is the need for the hidden field in the form if the data is being passed either via the URL or some other way</p>
  
  <p>I've also noticed on some sites that they have things like Form Keys and the username stored in meta tags in the page header???</p>
  
  <p>EDIT:</p>
  
  <pre><code>public function beforeFilter()
  {
  
          $this-&gt;set('authUser', $this-&gt;Auth-&gt;user());
  
          //
  
          $user = $this-&gt;Auth-&gt;user();
  
          if (!empty($user))
          {
              Configure::write('User', $user[$this-&gt;Auth-&gt;getModel()-&gt;alias]);
          }
  
  }
  
  public function beforeRender()
  {
      $user = $this-&gt;Auth-&gt;user();
  
      if (!empty($user))
      {
          $user = $user[$this-&gt;Auth-&gt;getModel()-&gt;alias];
      }
      $this-&gt;set(compact('user'));
  }
  
  
  // NEW VERSION
  function settings()
      {
          $this-&gt;layout = 'page';
  
          $this-&gt;set('title_for_layout', 'Edit Profile');
  
          $this-&gt;User-&gt;id = $user['id'];
  
          if (empty($this-&gt;data))
          {
              $this-&gt;data = $this-&gt;User-&gt;read();
          }
          else
          {
              if ($this-&gt;User-&gt;save($this-&gt;data))
              {
                  $this-&gt;Session-&gt;setFlash('Your settings have been updated', 'flash', array('myclass' =&gt; 'success'));
                  $this-&gt;redirect(array('controller' =&gt; 'users', 'action' =&gt; 'settings'));
              }
          }
      }
  </code></pre>