diff options
author | xue <> | 2007-06-29 17:41:20 +0000 |
---|---|---|
committer | xue <> | 2007-06-29 17:41:20 +0000 |
commit | 4a9dd5c8513ed96d1e0cf43e370b170dc38fb502 (patch) | |
tree | f41bbf25ac5bbc8d0b656c3e7c087e40b09b38b1 /demos/blog-tutorial/samples/day5/blog/protected/pages/users/NewUser.php | |
parent | 2d266a7994c57e9a13cccecacf8940e11263614f (diff) |
finished blog-tutorial.
Diffstat (limited to 'demos/blog-tutorial/samples/day5/blog/protected/pages/users/NewUser.php')
-rw-r--r-- | demos/blog-tutorial/samples/day5/blog/protected/pages/users/NewUser.php | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/demos/blog-tutorial/samples/day5/blog/protected/pages/users/NewUser.php b/demos/blog-tutorial/samples/day5/blog/protected/pages/users/NewUser.php new file mode 100644 index 00000000..76e8cb88 --- /dev/null +++ b/demos/blog-tutorial/samples/day5/blog/protected/pages/users/NewUser.php @@ -0,0 +1,45 @@ +<?php
+
+class NewUser extends TPage
+{
+ /**
+ * Checks whether the username exists in the database.
+ * This method responds to the OnServerValidate event of username's custom validator.
+ * @param mixed event sender
+ * @param mixed event parameter
+ */
+ public function checkUsername($sender,$param)
+ {
+ // valid if the username is not found in the database
+ $param->IsValid=UserRecord::finder()->findByPk($this->Username->Text)===null;
+ }
+
+ /**
+ * Creates a new user account if all inputs are valid.
+ * This method responds to the OnClick event of the "create" button.
+ * @param mixed event sender
+ * @param mixed event parameter
+ */
+ public function createButtonClicked($sender,$param)
+ {
+ if($this->IsValid) // when all validations succeed
+ {
+ // populates a UserRecord object with user inputs
+ $userRecord=new UserRecord;
+ $userRecord->username=$this->Username->Text;
+ $userRecord->password=$this->Password->Text;
+ $userRecord->email=$this->Email->Text;
+ $userRecord->role=(int)$this->Role->SelectedValue;
+ $userRecord->first_name=$this->FirstName->Text;
+ $userRecord->last_name=$this->LastName->Text;
+
+ // saves to the database via Active Record mechanism
+ $userRecord->save();
+
+ // redirects the browser to the homepage
+ $this->Response->redirect($this->Service->DefaultPageUrl);
+ }
+ }
+}
+
+?>
\ No newline at end of file |