mmm te dejo un ejemplo de un controlador y la vista que use para una aplicacion web a lo mejor te sirve
controlador:
Código PHP:
Ver originalfunction form_users($id='') {
$error='';
if($this->input->post('action')) {
$rules['email'] = "required|valid_email";
$rules['password'] = "required";
$rules['username'] = "required";
$this->validation->set_rules($rules);
$fields['email'] = "Email";
$fields['password'] = "Password";
$fields['username'] = "Username";
$this->validation->set_fields($fields);
$this->validation->set_error_delimiters('<p class="error">', '</p>');
if ($this->validation->run()) {
if($this->input->post('id')=='') {
//insert registered user
$this->redux_auth->email_activation = false;
$this->redux_auth->default_group = 2;
//$psw = $this->randomText(5);
$redux = $this->redux_auth->register
(
$this->input->post('username'),
$this->input->post('password'),
$this->input->post('email'),
'mvrelocations',
'users'
);
if($redux) {
$error = "Los datos se guardaron correctamente<bbr/>";
}
else {
$error = "Los datos no se guardaron correctamente<bbr/>";
}
}
else {
$user = $this->admin_model->getUser($this->input->post('id'));
$pass = sha1($user[0]->hash.$_POST['password']); $_POST['password'] = $pass;
$id = $this->admin_model->saveUser($_POST);
if($id=='') {
$error = "Los datos se guardaron correctamente<bbr/>";
}
else {
$error = "Los datos no se guardaron correctamente<bbr/>";
}
}
}
else {
$error = $this->validation->error_string;
}
}
else {
$user = $this->admin_model->getUser($id);
}
'list_users' => $this->admin_model->list_users(),
'pst_data' => $user,
'error' => $error,
);
$this->template->write_view('content', 'manager/form_users', $data);
$this->template->render();
}
vista:
Código HTML:
Ver originalfunction borrarUser(id){
if(confirm('Desea eliminar este registro?')){
window.location=siteURL+"manager/delete_user/"+id;
}
}
<table summary="Submitted table designs"> <th scope="col">Id Usuario
</th> <th scope="col">Nombre
</th> <th scope="col">E-mail
</th> <th scope="col">Edici
ón
</th> <th scope="col"> </th> <?
foreach($list_users as $l):
?>
<td><?=$l->username?>
</td> <td><a href="<?=base_url()?>manager/form_users/
<?=$l->id?>">Edit
</a></td> <td><a class="borrar" href="javascript:;" onclick="borrarUser(<?=$l->id?>)">Borrar
</a></td> <?
endforeach;
?>
<?php echo $error;?>
<?php echo form_open('manager/form_users'); ?>
<h3>INGRESO DE USUARIOS
</h3> <?php echo form_input(array( 'name' => 'username','id'=> 'username','value' => set_value('username', @$pst_data[0]->username))); ?>
<?php echo form_input(array( 'name' => 'password', 'id' => 'password')); ?>
<?php echo form_input(array( 'name' => 'email', 'id' => 'email','value' => set_value('email', @$pst_data[0]->email))); ?>
<?php echo form_hidden('action', 'ok'); ?>
<?php echo form_hidden('id', @$pst_data[0]->id); ?>
<?php echo form_submit('enviar', 'Enviar', 'class="button"') ?>
<?php echo form_close(); ?>