Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'd say put those views in a template and you can load that template. It makes things look a bit neater. Your index function should look like this</p> <pre><code> function index() { $data['page_title'] = 'Sign up page'; $data['central_content'] = "sign_up"; $this-&gt;load-&gt;view('template'); } </code></pre> <p>In your template don't forget to load content, like thus;</p> <pre><code>&lt;?php $this-&gt;load-&gt;view($central_content); ?&gt; </code></pre> <p>Rearrange you register function to look like this;</p> <pre><code>function register() { #you should be autoloading these helpers tbh $this-&gt;load-&gt;helper(array('form', 'url')); $this-&gt;load-&gt;library('form_validation'); $this-&gt;form_validation-&gt;set_rules('username', 'Username', 'required|min_length[5]|max_length[12]|trim'); $this-&gt;form_validation-&gt;set_rules('password', 'Password', 'required|md5|trim'); $this-&gt;form_validation-&gt;set_rules('username', 'Username', 'callback_usernameTaken'); if ($this-&gt;form_validation-&gt;run()) { $username = $this-&gt;input-&gt;post('username'); $password = $this-&gt;input-&gt;post('password'); #Learn to use flashdata, it helps. if($this-&gt;membership-&gt;newUser($username, $password)){ $this-&gt;session-&gt;set_userdata('status', 'OK'); $this-&gt;session-&gt;set_userdata('username', $username); redirect('home'); } }else{ $this-&gt;index(); } } #You specified a callback but there's no callback function in your class? Here's how you go about it. Public function usernameTaken(){ #callbacks should return true or false if ($this-&gt;membership-&gt;usernameTaken($username)) { return true; } else { #You can set your own validation message in the case it's false. $this-&gt;form_validation-&gt;set_message('usernameTaken', 'The selected username already exists'); return false; } } </code></pre> <p>Your model is ok, try change the the funcs to this</p> <pre><code> function newUser($username, $password) { $newMember = array('username' =&gt; $username, 'password' =&gt; $password); return ($this-&gt;db-&gt;insert('membership', $newMember)) ? true : false; } function usernameTaken($username) { #your query, requires a select * in a case where it's clearly not needed. Little things like this slow down your query.Try, $query = $this-&gt;db-&gt;where('username', $username)-&gt;get('membership'); #Also num_rows() return ($query-&gt;num_rows() &gt; 0) ? false : true; } </code></pre> <p>Just wrote this on here, so you'd have to test it out, but i'm sure it should be fine. Sorry i could't indent it properly though, it's a pain to do it on here :)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload