public static function factory($id) { if (isset($instance)) { return $instance; } else { $className = __CLASS__; self::$instance = new $className($id); return self::$instance; } }
public function adduserAction() { $form = new Jameen_Admin_Forms_User(); $user = new Jameen_User($this->getRequest()->getParam('id')); $form->addElement('hidden', 'id', array('value' => $user->id)); if ($user->id) { $form->account_id->setValue($user->account_id); $form->email->setValue($user->email); $form->user_name->setValue($user->user_name); $form->fname->setValue($user->fname); $form->lname->setValue($user->lname); $form->password->setValue($user->password); $form->role->setValue($user->role); $form->phone->setValue($user->phone); $form->gender->setValue($user->gender); $form->active->setValue($user->active); $form->image->setValue($user->image); $form->updated->setValue($user->updated); } if ($this->_request->isPost()) { $formData = $this->_request->getPost(); //print_r($formData); die; if ($form->isValid($formData)) { //write code to save into databse $user->account_id = $formData['account_id']; $user->email = $formData['email']; $user->user_name = $formData['user_name']; $user->fname = $formData['fname']; $user->lname = $formData['lname']; $user->password = $formData['password']; $user->role = $formData['role']; $user->phone = $formData['phone']; $user->gender = $formData['gender']; $user->active = $formData['active']; $user->image = $formData['image']; $user->updated = $formData['updated']; //print_r($formData); die; $id = $user->save(); $message = new Jameen_Alerts_Internal('User saved successfully', 'success', 'accounts', 'user', 'admin'); $this->_redirect("/admin/accounts/user/id/{$user->id}"); } else { $form->populate($formData); } } $this->view->errors = array(); foreach ($form->getMessages() as $field => $msgs) { foreach ($msgs as $msg) { $this->view->errors[$field] = $msg; break; } } $this->view->form = $form; }