I'm happy a bit of a variable scoping problem. Maybe I just need more coffee...
Here's my (simplified) code - this is in CodeIgniter 2:
class Agent extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('agent_model');
// Get preliminary data that will be often-used in Agent functions
$user = $this->my_auth_library->get_user();
$agent = $this->agent_model->get_agent($user->id);
}
public function index()
{
$this->template->set('info', $this->agent_model->get_info($agent->id));
$this->template->build('agent/welcome');
}
Unfortunately, when I run the index function, I'm told:
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: agent
Filename: controllers/agent.php
Line Number: 51
Line 51 is the first line of the index function. What's going wrong? Is this a scope issue or something else?
Thanks!