Welcome Guest, Not a member yet? Register   Sign In
A little lost.
#1

[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>

&lt;?php echo validation_errors(); ?&gt;

&lt;?php form_open('users/register'); ?&gt;

<label for='email'>E-mail</label>
&lt;input type='input' name='email' /&gt;&lt;br />

<label for='username'>Username</label>
&lt;input type='input' name='username' /&gt;&lt;br />

<label for='password'>Password</label>
&lt;input type='input' name='password' /&gt;&lt;br />

<label for='passconf'>Confirm Password</label>
&lt;input type='input' name='passconf' /&gt;&lt;br />

&lt;input type='submit' name='submit' value='Register' /&gt;
&lt;/form&gt;

My success view - success.php

Code:
<a href='&lt;?php base_url() ?&gt;'>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
#2

[eluser]Unknown[/eluser]
Ah, silly error. Apologies.

I missed a succeeding parenthesis in the user model.




Theme © iAndrew 2016 - Forum software by © MyBB