HosipLan

Untitled

Jul 21st, 2012
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.26 KB | None | 0 0
  1. /** @var Table\ActiveRow */
  2. private $user;
  3.  
  4. public function actionDefault($id)
  5. {
  6.     $this->user = $this->db->table('user')->get($id);
  7.  
  8.     if (!$this['form']->isSubmitted()) { // nevolat databázi zbytečně
  9.         $this['form']->setDefaults(array(
  10.             'user' => array(
  11.                 'home' => $this->user->home->toArray(),
  12.                 'correspondence' => $this->user->correspondence->toArray(),
  13.                 'billing' => $this->user->billing->toArray(),
  14.             ) + $this->user->toArray()
  15.         ));
  16.     }
  17. }
  18.  
  19.  
  20. protected function createComponentForm()
  21. {
  22.     $form = new UI\Form;
  23.  
  24.     $form['user'] = new UserContainer;
  25.     $form['user']['home'] = new AddressContainer;
  26.     $form['user']['correspondence'] = new AddressContainer;
  27.     $form['user']['billing'] = new AddressContainer;
  28.  
  29.     $form->addSubmit();
  30.     $form->onSuccess[] = $this->formSubmitted;
  31.  
  32.     return $form;
  33. }
  34.  
  35.  
  36. public function formSubmitted(UI\Form $form)
  37. {
  38.     // validace
  39.  
  40.     // user
  41.     $user = $form->values['user'];
  42.     unset($user['billing'], $user['home'], $user['correspondence']);
  43.     $this->user->update($user);
  44.  
  45.     // address
  46.     $this->user->home->update($form->values['user']['home']);
  47.     $this->user->billing->update($form->values['user']['billing']);
  48.     $this->user->correspondence->update($form->values['user']['correspondence']);
  49.  
  50.     $this->redirect(...
  51. }
Advertisement
Add Comment
Please, Sign In to add comment