Форма:
<?php echo validation_errors(); ?>
<?php echo form_open('master/add_user'); ?>
<p>username: <input type="text" name="username" value="<?php echo set_value('username'); ?>" /></p>
<p>password: <input type="text" name="password" value="<?php echo set_value('password'); ?>" /></p>
<div><input type="submit" value="go" /></div>
</form>
Контроллер:
<?php
class Master extends CI_Controller {
function dashboard()
{
$this->load->view('master/dashboardview');
}
function add_user()
{
$this->form_validation->set_rules('username', 'username', 'required');
$this->form_validation->set_rules('password', 'password', 'required');
if ($this->form_validation->run() === FALSE)
{
$this->load->view('master/dashboardview');
}
else
{
$this->load->model('user_model');
$this->user_model->add_user();
$this->load->view('master/success');
}
}
}
?>
Модель:
<?php
class User_model extends CI_Model {
function __construct()
{
parent::__construct();
}
function add_user()
{
$userInfo = array(
'username' => $_POST['username'],
'password' => $_POST['password'],
);
$this->db->insert('users', $userInfo);
}
}
?>
хелперы и библиотеки autoload
upd
Есть ли разница и какая
'username' => $_POST['username'],
или
'username' => $this->input->post('username'),