I have a controller that that will have many functions, I notice that my get_participants function does not run, when I load my welcome view, because when I try to use <?php echo $product ?> I get undefined variable exception.
I do not wish to have everything in my index function that loads the welcome view, but many functions that create one view. What is the proper way to invoke this controller so that it runs every function inside the class, or is there some better way I should be doing this?
class Welcome extends CI_Controller
{
function __construct()
{
parent::__construct();
$this->load->helper('url');
$this->load->library('tank_auth_groups','','tank_auth');
$this->load->model('Participant_model');
}
function index()
{
if (!$this->tank_auth->is_logged_in()) {
redirect('/auth/login/');
} else {
$data['user_id'] = $this->tank_auth->get_user_id();
$data['username'] = $this->tank_auth->get_username();
$this->load->view('welcome', $data);
}
}
public function get_participants()
{
$data['product'] = $this->Participant_model->get_all_records();
$this->load->view('welcome', $data);
}
}
View
Hi, <strong>
<?php echo $username; ?></strong>! You are logged in now.
<?php echo anchor('/auth/logout/', 'Logout'); ?>
<?php echo $product; ?>