Forum Moderators: coopster

Message Too Old, No Replies

PHP advice requested (Kohana experience a plus).

         

megaman732

5:17 am on Feb 9, 2010 (gmt 0)

10+ Year Member



I've been working with PHP (as a hobby) for about a year now. I don't know what you would consider me at this point, I'm not an expert by any means, but I dont think I'm a noob either. I am very close to finishing my first site.

Because this is a hobby to me, I dont really have anyone I can turn towards to look over my code and give me any advice on how im doing things, which brings me here. I was wondering if anybody wouldn't mind taking a look at my code to offer any kind of advice. I would hate to put something out that isnt quite as ready as it seems. I'm using Kohana, if that makes a big difference to anybody.

If any (trustworthy) developers are willing to help, I can email my code to you for a review, or I can post a few snippets up here directly.

TheMadScientist

5:32 am on Feb 9, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I'd drop a few examplified snipits that give us an idea of what you're doing, and if you read through the library and some senior member's posts you'll probably come away with some good ideas for basic 'foundation' type information. You could probably learn quite a bit or get some good ideas just by reading rocknbil's posts here in this forum. I don't use Kohana personally, so I'm probably not too much help.

megaman732

6:49 pm on Feb 9, 2010 (gmt 0)

10+ Year Member



For starters, this is the register function within my user model.

public function register(array& $user, $save = FALSE)
{
$user = new Validation($user);

// logged in users cant register
if(Auth::instance()->logged_in())
{
$user->add_error('registration', 'logged_in');
return FALSE;
}

// trim everything
$user->pre_filter('trim')

// everything is required
->add_rules('*', 'required')

// username must be 5 - 30 alphanumeric characters and available
->add_rules('username', 'length[5,30]', 'valid::alpha_numeric', array($this, 'username_available'))

// email must be valid format and available
->add_rules('email', 'valid::email', array($this, 'email_available'))

// password must be 5 - 15 characters and alpha dash
->add_rules('password', 'length[5,15]', 'valid::alpha_dash')

// gender must be either male or female. capitalize first letter
->add_rules('gender', array($this, 'valid_gender'))
->post_filter('ucfirst', 'gender')

// dob must be a valid date, and user must be old enough.
->add_callbacks('date_of_birth', array($this, 'check_dob'))

// captcha must be entered correctly.
->add_rules('captcha', 'Captcha::valid');

// add the registration date
$this->registration_date = date::unix2mysql();

// validate the information
$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->add(ORM::factory('role', 'login'));
$this->save();
}
}
else
{
$user->add_error('registration', 'failed');
}

return $result;
}

rocknbil

9:27 pm on Feb 9, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Out of context with the rest of the coding, it's hard to say if it's the best approach, one would have to dedicate a significant amount of time to reviewing the entire thing.

But I'll say, if that's an indicator of the way the rest of it is coded, it's a bazillion times better than most code I've seen . . . forge on.