[eluser]Unknown[/eluser]
Hi all, so I have tried to add the ability to register a user to my app. (I am only just starting with codeigniter). I tried to basically re-purpose the news tutorial. This is what I have done.
My users.php controller.
Code:
<?php
class Users extends CI_Controller{
public function __construct()
{
parent::__construct();
$this->load->model('users_model');
}
public function register()
{
$this->load->helper('form');
$this->load->library('form_validation');
$data['title'] = 'Register';
$this->form_validation->set_rules('username', 'Username', 'required|is_unique[users.username]');
$this->form_validation->set_rules('password', 'Password', 'required|matches[passconf]');
$this->form_validation->set_rules('passconf', 'Confirm E-Mail', 'required');
$this->form_validation->set_rules('email', 'E-Mail', 'required|valid_email|is_unique[users.email]');
if($this->form_validation->run() === FALSE)
{
$this->load->view('templates/header', $data);
$this->load->view('users/register');
$this->load->view('templates/footer');
}
else
{
$this->user_model->set_user();
$this->load->view('users/success');
}
}
}
Here is my users_model.php
Code:
<?php
class Users_model extends CI_Model {
public function set_user()
{
$pass = sha1($this->input->post('password');
$data = array(
'username' => $this->input->post('username'),
'password' => $pass,
'email' => $this->input->post('email');
);
return $this->db->insert('users', $data);
}
}
?>
My view - register.php
Code:
<h2>Register</h2>
<?php echo validation_errors(); ?>
<?php form_open('users/register'); ?>
<label for='email'>E-mail</label>
<input type='input' name='email' /><br />
<label for='username'>Username</label>
<input type='input' name='username' /><br />
<label for='password'>Password</label>
<input type='input' name='password' /><br />
<label for='passconf'>Confirm Password</label>
<input type='input' name='passconf' /><br />
<input type='submit' name='submit' value='Register' />
</form>
My success view - success.php
Code:
<a href='<?php base_url() ?>'>Return</a>
and finally I have added the following to the routes -
Code:
$route['register'] = 'users/register';
$route['users/register'] = 'users/register';
However, nothing is displayed when I point my browser to the register controller.
I know the controller is being called as if I change the model in the register controller to an unassigned model I get an error -
Quote:Unable to locate the model you have specified: not-a-real_model
Any ideas?
Thanks,
Dom