Advertisement
Guest User

Untitled

a guest
Feb 14th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1. function user_registration($user_name, $user_email, $user_pass, $address,
  2. $city, $postalcode, $country, $phone, $mobilephone)
  3.  
  4. class User {
  5.  
  6. public function setName($name) {
  7. $this->name = $name;
  8. }
  9.  
  10. [...]
  11.  
  12. public function register() {
  13.  
  14. //Validate input
  15. if (empty($this->name))
  16. $this->errors[] = "ERROR, Username must not be emtpy";
  17.  
  18. //Add the user to the database
  19. //Your SQL query
  20. return empty($this->errors);
  21. }
  22.  
  23. }
  24.  
  25. $user = new User();
  26. $user->setName("Peter");
  27. $success = $user->register();
  28.  
  29. if (!$success)
  30. echo "ERRORS OCCURED: ".print_r($user->errors, true);
  31.  
  32. function user_registration(array $data) {
  33. // work with $data['name']
  34. // and $data['email']
  35. // ...
  36. }
  37.  
  38. user_registration(array(
  39. 'name' => 'blah',
  40. 'email' => 'test@example.com',
  41. 'pass' => '123456',
  42. // and so on
  43. ));
  44.  
  45. function user_registration(array $user_info)
  46. {
  47. // process $user_info;
  48. }
  49.  
  50. User Data: $user_name, $user_pass
  51. Address Data: $address, $city, $postalcode, $country
  52. Contact Data: $user_email, $phone, $mobilephone
  53.  
  54. function user_registration(User $user, Address $address, Contact $contact)
  55.  
  56. function user_registration(User $user)
  57.  
  58. $user = new User('johndoe', 'secretsauce');
  59. $user->setAddress(new Address('Doe Street', 'Doe Town', 12345, 'Neverland'));
  60. $user->setContact('jdoe@example.com', '+123 12345', '+123 54321');
  61. user_registration($user);
  62.  
  63. user_registration(new User($credentials, $address, $contact));
  64.  
  65. $user = new User(new Credentials('johndoe', 'secretsauce'));
  66. $user->setAddress(new Address('Doe Street', 'Doe Town', 12345, 'Neverland'));
  67. $user->setContact(new Contact('jdoe@example.com', '+123 12345', '+123 54321'));
  68. user_registration($user);
  69.  
  70. $user = new User($credentials);
  71. $user->setAddress($address);
  72. $user->setContact($contact);
  73. $user->register();
  74.  
  75. $user = new User;
  76. $user->setAddress($address);
  77. $user->setContact($contact);
  78. $user->register($credentials);
  79.  
  80. private var $name;
  81.  
  82. public function register()
  83.  
  84. $fields = array('field1', 'field2');
  85. function register (array $values, array $keys)
  86. {
  87. $data = array();
  88. foreach ($keys as $one)
  89. {
  90. if (isset($values[$one])) $data[$one] = $values[$one];
  91. }
  92. // or you can use array functions like array_flip and after - array intersect
  93. }
  94.  
  95. fields=explode(",","name,surname,lastname,street,city,region,zip,country");
  96. user_registration($fields);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement