public function action_edit($id = null) { $customer = Model_Customer::find($id); $val = Model_Customer::validate('edit'); if ($val->run()) { $customer->name = Input::post('name'); $customer->email = Input::post('email'); $customer->phone = Input::post('phone'); $customer->address = Input::post('address'); $customer->website = Input::post('website'); if ($customer->save()) { Session::set_flash('success', e('Updated customer #' . $id)); Response::redirect('admin/customers'); } else { Session::set_flash('error', e('Could not update customer #' . $id)); } } else { if (Input::method() == 'POST') { $customer->name = $val->validated('name'); $customer->email = $val->validated('email'); $customer->phone = $val->validated('phone'); $customer->address = $val->validated('address'); $customer->website = $val->validated('website'); Session::set_flash('error', $val->error()); } $this->template->set_global('customer', $customer, false); } $this->template->title = "Customers"; $this->template->content = View::forge('admin/customers/edit'); }
public function action_edit($id = null) { if ($customer = Model_Customer::find($id)) { $val = Model_Customer::validate('edit'); if ($val->run()) { $customer->description = Input::post('description'); $customer->contact_person = Input::post('contact_person'); $customer->phone = Input::post('phone'); $customer->email = Input::post('email'); if ($customer->save()) { Session::set_flash('success', e('Updated customer #' . $id)); Response::redirect('admin/customers/view/' . $customer->id); } else { Session::set_flash('error', e('Could not update customer #' . $id)); } } else { if (Input::method() == 'POST') { $customer->description = $val->validated('description'); $customer->contact_person = $val->validated('contact_person'); $customer->phone = $val->validated('phone'); $customer->email = $val->validated('email'); Session::set_flash('error', $val->error()); } $this->template->set_global('customer', $customer, false); } $this->template->title = "Customers » " . $customer->description . " » Edit"; $this->template->content = View::forge('admin/customers/edit'); } else { Session::set_flash('error', 'Cannot find the selected customer.'); Response::redirect_back('admin/customers'); } }