title: PHP advice please. (Kohana experience a plus)
body: <p>I've been working with PHP for about a year, but I do it as a hobby. I dont have anybody I can go to as a teacher or a mentor to give me advice on what I may be doing completely wrong, or what I could do better. I've done quite a few different things within that year, so I wouldnt consider myself a complete noob.</p>
  
  <p>Anyways, I have just started using a framework (Kohana), and there really arent that many tutorials out there, so I'm not entirely sure if I'm doing things in a good way.</p>
  
  <p>I have a few code snippets that I would like to post to get some feedback pertaining to what I just said.</p>
  
  <p>For Starters</p>
  
  <h2>User Controller</h2>
  
  <pre><code>class User_Controller extends Template_Controller{
  
      public function register()
  {
      // logged in users cant register
      if($this-&gt;logged_in)
      {
          url::redirect('user/profile');
      }
  
      // initially show an empty form
      $form = $errors = array
      (
          'username'      =&gt; '',
          'email'         =&gt; '',
          'password'      =&gt; '',
          'gender'        =&gt; '',
          'dob_month'     =&gt; '',
          'dob_day'       =&gt; '',
          'dob_year'      =&gt; '',
          'date_of_birth' =&gt; '',
          'captcha'       =&gt; '',
          'registration'  =&gt; ''
      );
  
      // check for a form submission
      if($this-&gt;input-&gt;post('register'))
      {
          // get the form
          $post = $this-&gt;input-&gt;post();
  
          // prepare the data for validation
          $post['date_of_birth'] = "{$post['dob_year']}-{$post['dob_month']}-{$post['dob_day']}";
  
          // create a new user
          $user = ORM::factory('user');
  
          // validate and register the user. 
          if($user-&gt;register($post, TRUE))
          {
              // SEND EMAIL
  
              // login using the collected data
              if(Auth::instance()-&gt;login($post-&gt;username, $post-&gt;password, TRUE))
              {
                  // redirect the user to the profile page
                  //url::redirect("user/profile/{$user-&gt;id}");
              }
          }
  
          // get validation errors and repopulate the form
          $form   = arr::overwrite($form,   $post-&gt;as_array());
          $errors = arr::overwrite($errors, $post-&gt;errors('registration_errors'));
      }
  
      // template variables
      $this-&gt;template-&gt;title = 'Sign Up';
      $this-&gt;template-&gt;body  = new View('layout_1');
  
      // layout variables
      $this-&gt;template-&gt;body-&gt;left  = new View('user/registration_form');
      $this-&gt;template-&gt;body-&gt;right = 'Right Side Content';
  
      // registration form variables
      $this-&gt;template-&gt;body-&gt;left-&gt;form    = $form;
      $this-&gt;template-&gt;body-&gt;left-&gt;errors  = $errors;
      $this-&gt;template-&gt;body-&gt;left-&gt;captcha = new Captcha('register');
  }
  }
  </code></pre>
  
  <h2>Register Function within User_Model</h2>
  
  <pre><code>class User_Model extends ORM{
  
      public function register(array&amp; $user, $save = FALSE)
  {
      $user = new Validation($user);
  
      // logged in users cant register
      if(Auth::instance()-&gt;logged_in())
      {
          $user-&gt;add_error('registration', 'logged_in');
          return FALSE;
      }
  
      // trim everything
      $user-&gt;pre_filter('trim')
  
          // everything is required
          -&gt;add_rules('*', 'required')
  
          // username must be 5 - 30 alphanumeric characters and available
          -&gt;add_rules('username', 'length[5,30]', 'valid::alpha_numeric', array($this, 'username_available'))
  
          // email must be valid format and available
          -&gt;add_rules('email', 'valid::email', array($this, 'email_available'))
  
          // password must be 5 - 15 characters and alpha dash
          -&gt;add_rules('password', 'length[5,15]', 'valid::alpha_dash')
  
          // gender must be either male or female. capitalize first letter
          -&gt;add_rules('gender', array($this, 'valid_gender'))
          -&gt;post_filter('ucfirst', 'gender')
  
          // dob must be a valid date, and user must be old enough.
          -&gt;add_callbacks('date_of_birth', array($this, 'check_dob'))
  
          // captcha must be entered correctly.
          -&gt;add_rules('captcha', 'Captcha::valid');
  
      // add the registration date
      $this-&gt;registration_date = date::unix2mysql();  // helper function transforms the current unix to mysql datetime format
  
      // validate the information. an ORM function.
      $result = parent::validate($user, $save);
  
      // was the user info valid?
      if($result === TRUE)
      {
          // was the user saved?
          if($save === TRUE)
          {
              // add a login role
              $this-&gt;add(ORM::factory('role', 'login'));
              $this-&gt;save();
          }
      }
      else
      {
          $user-&gt;add_error('registration', 'failed');
      }
  
      return $result;
  }
  }
  </code></pre>
  
  <p>Mostly all my models follow the same format when validating info.</p>
  
  <p>I have some other things I would appreciate feedback on as well, but I dont want to overwhelm anybody.</p>
  
  <h2>Thanks a lot for your time</h2>
  
  <p><b>EDIT:</b> I'm sorry, I should've posted both the user controller and model. I've been reading alot about how models should be fat, and controllers should be skinny. Thats why I created a register function in the model to validate the info instead of doing so within the controller. The register function takes an array, but turns that array into a validation object so that I can retrieve the user input, and the errors. I've seen a few tutorials on Kohana where it was done this way.</p>