public static function factory($id) { if (isset($instance)) { return $instance; } else { $className = __CLASS__; self::$instance = new $className($id); return self::$instance; } }
public function addAction() { $form = new Jameen_Admin_Forms_Accounts(); $accounts = new Jameen_Accounts($this->getRequest()->getParam('id')); $form->addElement('hidden', 'id', array('value' => $accounts->id)); if ($accounts->id) { $form->reply_to->setValue($accounts->reply_to); $form->html_signature->setValue($accounts->html_signature); $form->primary_phone->setValue($accounts->primary_phone); $form->cell_phone->setValue($accounts->cell_phone); $form->fax->setValue($accounts->fax); $form->company->setValue($accounts->company); $form->address->setValue($accounts->address); $form->address2->setValue($accounts->address2); $form->city->setValue($accounts->city); $form->state->setValue($accounts->state); $form->zip->setValue($accounts->zip); $form->email->setValue($accounts->email); $form->report_template_id->setValue($accounts->report_template_id); $form->followup_template_id->setValue($accounts->followup_template_id); $form->followup_enabled->setValue($accounts->followup_enabled); $form->sms_enabled->setValue($accounts->sms_enabled); } if ($this->_request->isPost()) { $formData = $this->_request->getPost(); //print_r($formData); die; if ($form->isValid($formData)) { //write code to save into databse $accounts->reply_to = $formData['reply_to']; $accounts->html_signature = $formData['html_signature']; $accounts->primary_phone = $formData['primary_phone']; $accounts->cell_phone = $formData['cell_phone']; $accounts->fax = $formData['fax']; $accounts->company = $formData['company']; $accounts->address = $formData['address']; $accounts->address2 = $formData['address2']; $accounts->city = $formData['city']; $accounts->state = $formData['state']; $accounts->zip = $formData['zip']; $accounts->email = $formData['email']; $accounts->report_template_id = $formData['report_template_id']; $accounts->followup_template_id = $formData['followup_template_id']; $accounts->form_template_id = $formData['form_template_id']; $accounts->followup_enabled = $formData['followup_enabled']; $accounts->sms_enabled = $formData['sms_enabled']; //print_r($formData); die; $id = $accounts->save(); $message = new Jameen_Alerts_Internal('Accounts saved successfully', 'success', 'accounts', 'index', 'admin'); $this->_redirect("/admin/accounts"); } 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; }