Advertisement
Guest User

Untitled

a guest
Jun 8th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.72 KB | None | 0 0
  1.     public function action_update($id)
  2.     {
  3.         $tpl = Haml::Factory('admin/users/create');
  4.         $user = ORM::Factory('user', (int) $id);
  5.  
  6.         $data = array(
  7.             'username', 'mail', 'birthdate'
  8.         );
  9.         if($_POST)
  10.         {
  11.             foreach($data as $field)
  12.             {
  13.                 $user->$field = $_POST[$field];
  14.             }
  15.            
  16.             if(!empty($_POST['password']))
  17.                 {
  18.                 var_dump($_POST);
  19.                 $user->password = $_POST['password'];
  20.                 }
  21.                
  22.             $user->birthdate = date("Y-m-d", strtotime($_POST['birthdate']));
  23.  
  24.             if($user->check())
  25.             {
  26.                 $user->save();
  27.             }
  28.             else
  29.             {
  30.                 $tpl->set('errors', $user->validate()->errors('form/user'));
  31.                 $tpl->set($_POST);
  32.             }
  33.         }
  34.  
  35.         $tpl->set($user->as_array());
  36.  
  37.         $this->request->response = $tpl;
  38.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement