Note that there are some explanatory texts on larger screens.

plurals
  1. POCodeigniter: Easiest way to make users details grabbed from a data base accessible by methods in any controller or method
    text
    copied!<p>I already asked this question, but in a way that confused people.</p> <p>So what I want to achieve is this:</p> <p>I have a method get_user_by_email() and it is used to grab the row from the database table of a user who is logged out.</p> <pre><code>public function get_user_by_email($email_post = '') //post email grabbed from reset password controller { if (empty($email_post)) { return FALSE; } $query = $this-&gt;db-&gt;query("SELECT * FROM users WHERE email = '$email_post'"); $query-&gt;row(); $row = $query-&gt;row(); $user_id = $row-&gt;{'id'}; $email = $row-&gt;{'email'}; $first_name = $row-&gt;{'first_name'}; $last_name = $row-&gt;{'last_name'}; //e.g. example below is just an example and obviously wouldn't work but the variables are what I use in my mysql querys ...eg. WHERE email = $email etc return $email; return $first_name; return $last_name; return $user_id; } </code></pre> <p>The above code doesn't work and I know this but I was giving an example of what I am doing with the data I get from the row.</p> <p>I just want to some how make this available to my reset_password controller through out, then my confirm_reset_code controller and then finally my create_new_password controller. </p> <p>How would I do this?</p> <p><strong>NEW MODEL</strong></p> <pre><code>class Get_user_by_email extends CI_Model { public function __construct() { parent::Ci_Model(); } public function process($email_post = '') //post email grabbed from reset password controller { if (empty($email_post)) { return FALSE; } return $this-&gt;db-&gt;query("SELECT * FROM users WHERE email = '$email_post'"); } } </code></pre> <p><strong>NEW CONTROLLER</strong></p> <pre><code>&lt;?php class Account extends FH_Controller { public function __construct() { parent::__construct(); $this-&gt;load-&gt;model('get_user_by_email'); } public function reset_password() { $this-&gt;load-&gt;view('reset_password'); if ($this-&gt;get_user_by_email-&gt;process($this-&gt;input-&gt;post('e-mail'))) { $query = $this-&gt;get_user_by_email-&gt;process(); print_r($query); } } public function confirm_reset_code() { $this-&gt;load-&gt;view('confirm_reset_code'); } public function create_new_password() { $this-&gt;load-&gt;view('create_new_password'); } } </code></pre> <p>I enter email and nothing is returned to browser. </p>
 

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