Created
August 31, 2011 13:40
-
-
Save mattjmorrison/1183555 to your computer and use it in GitHub Desktop.
PHP/CodeIgniter Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function create_offer(){ | |
$merchant = new Merchant(); | |
$merchant->where('id', 1);//TODO get currently logged in merchant | |
$merchant->get(); | |
$this->load->library('form_validation'); | |
$this->form_validation->set_rules('description', 'Description', 'required'); | |
$this->form_validation->set_rules('from_time', 'From Time', 'required'); | |
$this->form_validation->set_rules('to_time', 'To Time', 'required'); | |
$this->form_validation->set_rules('deal', 'Deal', 'required'); | |
$fields = array(); | |
$deal = ''; | |
if (array_key_exists('deal', $this->input->post())){ | |
$deal = $this->input->post('deal'); | |
if ($deal != ''){ | |
$fields = $deal::$fields; | |
} | |
} | |
if ($this->form_validation->run()){ | |
$deal_fields = array(); | |
foreach ($fields as $field_name => $field_value){ | |
$deal_fields[$field_name] = $this->input->post($field_name); | |
} | |
$offer = new Deal_Model(); | |
$offer->merchantId = $merchant->id; | |
$offer->description = $this->input->post('description'); | |
$offer->from = getSqlDateFromPostData($this->input->post('from_time')); | |
$offer->to = getSqlDateFromPostData($this->input->post('to_time')); | |
$offer->details = serialize($deal_fields); | |
$offer->save(); | |
$this->redirect("merchant/dashboard"); | |
} | |
else { | |
$context = $this->getBaseContext(); | |
$context['data'] = $this->input->post(); | |
$context['fields'] = $fields; | |
$context['deal'] = $deal; | |
$this->load->view('merchant/dashboard', $context); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment