[eluser]LeePR[/eluser]
[quote author="coolfactor" date="1189030418"]Really important that you provide _real_ code examples, or it misleads us and we can't help you.
I can't see what else could be wrong.[/quote]
Oh, so it's an error in my code? I was thinking that for some reason CI might not let me load models within views. OK here are two scenarios (with real code). My model looks exactly the same for both examples:
Code:
<?php
class State extends Model {
function Model_state() {
parent::Model();
}
function generateStateDropDown() {
echo "TEST!";
}
}
?>
Scenario 1: The model is loaded within the view. Here's my view:
Code:
<?php
echo "@ Beginning of view!<br/>";
//$this->load->model('State');
//$this->state->generateStateDropDown();
echo "@ End of view!<br/>";
?>
and here' my controller method:
Code:
function createAccount() {
$this->load->view('create_account');
$this->load->model('State');
$this->state->generateStateDropDown();
}
This works! And prints out
Quote:Test
@ Beginning of view!
@ End of view!
Scenario 2: I comment out the loading of the model in the controller, and make the view load the model. Here's my view:
Code:
<?php
echo "@ Beginning of view!<br/>";
$this->load->model('State');
$this->state->generateStateDropDown();
echo "@ End of view!<br/>";
?>
and here's my controller method:
Code:
function createAccount() {
$this->load->view('create_account');
//$this->load->model('State');
//$this->state->generateStateDropDown();
}
This doesn't work and prints out
Quote:
@ Beginning of view!
A PHP Error was encountered
Severity: Notice
Message: Undefined property: CI_Loader::$state
Filename: views/stateList.php
Line Number: 4
Fatal error: Call to a member function generateStateDropDown() on a non-object in /home/lee/Development/CodeIgniter_1.5.4/system/application/views/stateList.php on line 4