Note that there are some explanatory texts on larger screens.

plurals
  1. POAnother Codeigniter Property Undefined issue
    primarykey
    data
    text
    <p>I'm getting this, but I don't understand why.:</p> <pre><code>A PHP Error was encountered Severity: Notice Message: Undefined property: Menu::$menu_model Filename: controllers/menu.php Line Number: 16 Fatal error: Call to a member function get_menu() on a non-object in /home/.../modules/menu/controllers/menu.php on line 16 </code></pre> <p>I've looked at <a href="https://stackoverflow.com/questions/9923160/codeigniter-model-undefined-property">this</a>, <a href="https://stackoverflow.com/questions/5547912/codeigniter-undefined-property-error-on-model">that</a> and <a href="https://stackoverflow.com/questions/8440226/codeigniter-undefined-property-when-loading-a-model">the other</a>. But even with my simple code, it still breaks.</p> <p>The Controller </p> <pre><code>class Menu extends CI_Controller { /** * Constructor method */ public function __construct() { parent::__construct(); } function index($layout = -1) { $this-&gt;load-&gt;model('menu_model'); // There is no $this-&gt;menu_model at this point. If I echo it out, it says property undefined as well. $data['menu'] = $this-&gt;menu_model-&gt;get_menu($layout); // It fails on this line. $data['thisurl'] = $this-&gt;uri-&gt;uri_string(); $this-&gt;load-&gt;view('menu.php'); } } </code></pre> <p>The Model</p> <pre><code>class Menu_model extends CI_Model { public function get_menu($layout = -1) { $menu = array( 0 =&gt; array('href' =&gt; '/', 'label' =&gt; 'Home', FALSE), 1 =&gt; array('href' =&gt; '/about', 'label' =&gt; 'About', FALSE), 2 =&gt; array('href' =&gt; '/help', 'label' =&gt; 'Help', FALSE) ); return $menu; } } </code></pre> <p>The file is loaded successfully. If I change the class name to Menu_model_fail... I get an error, and if I change the load->model('menu_model_break') I also get an error. So I know it's loading the file correctly. </p>
    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.
 

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