I've gone ahead and added the createuserAction to my indexController to illustrate how we could reuse all the code previously written to validate and save creating a new user. If you want to view the change log to see the code I added to support this, you can view it here: [url=http://code.google.com/p/plushcode/source/detail?r=23]http://code.google.com/p/plushcode/source/detail?r=23[/url]


Here's what our createuserAction code looks like now


public function createuserAction()
{
// we're going to be creating a user
$userRepo = new user_UserRepository();
$user = $userRepo->getNewUser();

// pass the form the validator it needs to work with
$form = new forms_CreateUserForm(array('Validator' => new user_validation_Default($user)));

// find a user with id 1 in the DB
if ($this->getRequest()->isPost()) {
if($form->isValid($_POST)) {

$values = $form->getValues();

// let's update the user's email address to what was posted from the form
$user->setEmailAddress($values['email']);

// update the profile's nickname
$user->Profile->setNickname($values['nickname']);

// check to make sure the whole user object is valid with these new changes
if(!$user->isValid()) {
$this->view->errors = $user->getMessages();
} else {
$userRepo->save($user);
$this->view->message = "USER CREATED!";
}
}

}

$this->view->form = $form;
}

Ready for More?

Follow Me @jimplush