public function action_edit($id = null) { $setting = Model_Setting::find($id); $val = Model_Setting::validate('edit'); if ($val->run()) { $setting->setting_key = Input::post('setting_key'); $setting->setting_title = Input::post('setting_title'); $setting->setting_value = Input::post('setting_value'); $setting->setting_data_type_id = Input::post('setting_data_type_id'); if ($setting->save()) { Session::set_flash('success', e('Updated setting #' . $id)); Response::redirect('admin/settings/view/' . $setting->id); } else { Session::set_flash('error', e('Could not update setting #' . $id)); } } else { if (Input::method() == 'POST') { $setting->setting_key = $val->validated('setting_key'); $setting->setting_title = $val->validated('setting_title'); $setting->setting_value = $val->validated('setting_value'); $setting->setting_data_type_id = $val->validated('setting_data_type_id'); Session::set_flash('error', $val->error()); } $this->template->set_global('setting', $setting, false); } $this->template->set_global('data_types', Model_Setting_Data_Type::find('all', array('order_by' => array(array('name', 'asc'))))); $this->template->title = "Settings"; $this->template->content = View::forge('admin/settings/edit'); }
/** * The index action * * @access public * @return void */ public function action_index() { $settings = \Config::load('autoresponder.db'); // $autoResponder = Model_Setting::find(array('where' => array(array('meta_key', '=', 'auto-responders')))); if (\Input::post()) { $input = \Input::post(); if (!\Input::is_ajax()) { $val = Model_Setting::validate('create'); if (!$val->run()) { if ($val->error() != array()) { // show validation errors \Messages::error('<strong>There was an error while trying to create settings</strong>'); foreach ($val->error() as $e) { \Messages::error($e->get_message()); } } } else { try { \Config::save('autoresponder.db', array('logo_url' => $input['logo_url'], 'company_name' => $input['company_name'], 'address' => $input['address'], 'website' => $input['website'], 'phone' => $input['phone'], 'email_address' => $input['email_address'], 'sender_email_address' => $input['sender_email_address'], 'contact_us_email_address' => $input['contact_us_email_address'], 'instagram_account_name' => $input['instagram_account_name'], 'facebook_account_name' => $input['facebook_account_name'])); // $setting->save(); \Messages::success('Settings successfully created.'); \Response::redirect('admin/settings'); } catch (\Database_Exception $e) { // show validation errors \Messages::error('<strong>There was an error while trying to create settings.</strong>'); // Uncomment lines below to show database errors $errors = $e->getMessage(); \Messages::error($errors); } } } } \View::set_global('title', 'Settings'); \Theme::instance()->set_partial('content', $this->view_dir . 'index')->set('settings', $settings, false); }