Note that there are some explanatory texts on larger screens.

plurals
  1. POAdding A Data Array for redirect
    primarykey
    data
    text
    <p>My question of the day is this. After a successful login I want to to send the user_id in a data array to the control panel when it redirects. I have a lot of code here. 98% of it was code that was written from a authentication library and I'm afraid if I tinker too much with it now I'll end up breaking something else by trying to do one thing. Any help?</p> <pre><code>class Auth extends CI_Controller { function __construct() { parent::__construct(); $this-&gt;load-&gt;helper(array('form', 'url')); $this-&gt;load-&gt;library('form_validation'); $this-&gt;load-&gt;library('security'); $this-&gt;load-&gt;library('tank_auth'); $this-&gt;lang-&gt;load('tank_auth'); if ($this-&gt;tank_auth-&gt;is_logged_in()) { redirect('/cpanel/'); } else { redirect('/auth/login/'); } } function index() { } /** * Login user on the site * * @return void */ function login() { if ($this-&gt;tank_auth-&gt;is_logged_in()) { // logged in redirect('/cpanel'); } elseif ($this-&gt;tank_auth-&gt;is_logged_in(FALSE)) { // logged in, not activated redirect('/auth/send_again/'); } else { $data['login_by_username'] = ($this-&gt;config-&gt;item('login_by_username', 'tank_auth') AND $this-&gt;config-&gt;item('use_username', 'tank_auth')); $data['login_by_email'] = $this-&gt;config-&gt;item('login_by_email', 'tank_auth'); $this-&gt;form_validation-&gt;set_rules('login', 'Login', 'trim|required|xss_clean'); $this-&gt;form_validation-&gt;set_rules('password', 'Password', 'trim|required|xss_clean'); $this-&gt;form_validation-&gt;set_rules('remember', 'Remember me', 'integer'); // Get login for counting attempts to login if ($this-&gt;config-&gt;item('login_count_attempts', 'tank_auth') AND ($login = $this-&gt;input-&gt;post('login'))) { $login = $this-&gt;security-&gt;xss_clean($login); } else { $login = ''; } $data['errors'] = array(); if ($this-&gt;form_validation-&gt;run()) { // validation ok if ($this-&gt;tank_auth-&gt;login( $this-&gt;form_validation-&gt;set_value('login'), $this-&gt;form_validation-&gt;set_value('password'), $this-&gt;form_validation-&gt;set_value('remember'), $data['login_by_username'], $data['login_by_email'])) { // success redirect('/cpanel'); } else { $errors = $this-&gt;tank_auth-&gt;get_error_message(); if (isset($errors['banned'])) { // banned user $this-&gt;_show_message($this-&gt;lang-&gt;line('auth_message_banned').' '.$errors['banned']); } elseif (isset($errors['not_activated'])) { // not activated user redirect('/auth/send_again/'); } else { // fail foreach ($errors as $k =&gt; $v) $data['errors'][$k] = $this-&gt;lang-&gt;line($v); } } } $this-&gt;template-&gt;set_layout('default')-&gt;enable_parser(false); $this-&gt;template-&gt;build('auth/login_form', $data); } } </code></pre> <p>Edit: </p> <p>So I have included the model with the controller however I'm getting a this error as I'v also included the model.</p> <pre><code>A PHP Error was encountered Severity: Notice Message: Undefined variable: id Filename: controllers/cpanel.php Line Number: 20 A PHP Error was encountered Severity: Warning Message: Cannot modify header information - headers already sent by (output started at /home/xtremer/public_html/system/core/Exceptions.php:170) Filename: core/Common.php Line Number: 409 A Database Error Occurred Error Number: 1066 Not unique table/alias: 'users' SELECT * FROM (`users`, `users`) JOIN `user_profiles` ON `users`.`id` = `user_profiles`.`user_id` Filename: /home/xtremer/public_html/kowmanager/models/cpanel/dashboard.php Line Number: 38 </code></pre> <p>Model:</p> <pre><code>class Dashboard extends CI_Model { private $table_name = 'users'; // user accounts private $profile_table_name = 'user_profiles'; // user profiles function __construct() { parent::__construct(); $ci =&amp; get_instance(); $this-&gt;table_name = $ci-&gt;config-&gt;item('db_table_prefix', 'tank_auth').$this-&gt;table_name; $this-&gt;profile_table_name = $ci-&gt;config-&gt;item('db_table_prefix', 'tank_auth').$this-&gt;profile_table_name; } /** * Get user info by Id * * @param int * @param bool * @return object */ function get_user_info($id) { $this-&gt;db-&gt;select('*'); $this-&gt;db-&gt;from('users'); $this-&gt;db-&gt;join('user_profiles', 'users.id = user_profiles.user_id'); $query = $this-&gt;db-&gt;get($this-&gt;table_name); if ($query-&gt;num_rows() == 1) { return $data = $query-&gt;row(); } else { return NULL; } } } </code></pre>
    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.
 

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