Code snippets for symfony 1.x

Navigation

Refine Tags

Snippets tagged "copy"

Copy request data into the session

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
    }
}
by Eric Bartels on 2006-11-27, tagged copy  request  session  user