[eluser]cPage[/eluser]
Inside Controller
Code:
public function edit($id)
{
$this->data = array('header' => array('title' => $this->lang->line('factures_edit_title')),
'nav' => array('active'=>'factures_edit'),
'content' => array('facture' => $this->facture_model->get_facture($id),
'fields' => $this->facture_model->select_fields(),
'form_error' => $this->form_error,
'list_client'=> $this->client_model->select_list('id_client,client')));
$this->template->set('header', $this->config->item('theme_url').'header', $this->data['header'])
->set('nav', $this->config->item('theme_url').'user/nav', $this->data['nav'])
->set('content', $this->config->item('theme_url').'facture/edit', $this->data['content'])
->load($this->config->item('theme_url').'m_template');
}
Code:
public function update()
{
$this->validation();
if ($this->form_validation->run() == FALSE)
{
$this->form_error = TRUE;
$this->edit($this->input->post('id_facture'));
}
else
{
$id_facture = $this->input->post('id_facture');
$this->facture_model->update($this->input->post(),array('id_facture' => $id_facture));
$this->common->set_message('alert alert-success',sprintf($this->lang->line('factures_edit_message'),$this->input->post('facture')));
$this->index();
}
}
The view
Code:
<div class="page-header">
<h3><?=$this->lang->line($active.'_title')?></h2>
</div>
<div class="container">
<form class="form-horizontal" method="post" acti>
<?php
foreach($fields as $field)
{
$data = array('label'=>ucfirst($this->lang->line($field)),
'name'=>$field,
'help'=>$this->lang->line($active.'_'.$field.'_help'),
'success'=>$this->lang->line($active.'_'.$field.'_valid'));
switch($field)
{
case 'id_facture':
$data['type'] = 'hidden';
break;
case 'client_id':
$temp = array('type'=>'dropdown',
'list'=>$list_client,
'primary'=>'id_client',
'fieldlist'=>'client');
$data = array_merge($data,$temp);
break;
}
echo ($form_error)?form_input_controls($data,set_value($field)):form_input_controls($data,$facture->$field);
}
?>
<div class="control-group">
<div class="controls">
<button type="submit" class="btn"><?=$this->lang->line('edit_submit')?></button>
</div>
</div>
</form>
</div>