![]() |
|
Snippets |
|
Recently I needed to copy data that comes from a webform into the current session. Here is my solution ...
class myUser extends sfBasicSecurityUser { /** * Copy request data into the users session object * * @param array $exclude Fieldnames to exclude from copy */ public function copyRequestData ($exclude = array ()) { /// Get the request instance and its currently posted fieldnames $req = sfContext::getInstance ()->getRequest (); $fieldNames = $req->getParameterHolder ()->getNames (); /// Always exclude "posted" module and action $exclude[] = 'module'; $exclude[] = 'action'; /// Evaluate each fieldname and do a "lookup" if it can /// be copied foreach ($fieldNames as $fieldName) { if (!in_array ($fieldName, $exclude)) { $this->setAttribute ($fieldName, $req->getParameter ($fieldName, null)); } // end if } // end foreach } }