HosipLan

Untitled

Jun 25th, 2011
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.52 KB | None | 0 0
  1. class UsersFormMapper extends Nette\Object
  2. {
  3.     private static $map = array(
  4.         'name' => 'username',
  5.         // ...
  6.     );
  7.  
  8.  
  9.     public function __construct(Nette\Application\UI\Form $form);
  10.  
  11.  
  12.     public function save($entity)
  13.     {
  14.         foreach (self::$map as $f => $e) {
  15.             if (isset($this->form[$f])) {
  16.                 $this->form[$f]->setDefaultValue($entity->{$e});
  17.             }
  18.         }
  19.     }
  20.  
  21.  
  22.     public function load()
  23.     {
  24.         foreach (self::$map as $f => $e) {
  25.             if (isset($this->form[$f])) {
  26.                 $entity->{$e} = $this->form[$f];
  27.             }
  28.         }
  29.     }
  30.  
  31. }
Advertisement
Add Comment
Please, Sign In to add comment