CodeIgniter Forums

Full Version: error explanation
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]boytun[/eluser]
Hello friends.

I'm using in my application HMVC architecture, and I get this errors wich I can understand .
I try to load my module in the mvc view.
this the code of the module controller(widg_html.php):
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Widg_html extends MY_Controller {

public function __construct()
{
  parent::__construct();
  $this->load->model('mdl_widg_html');
}


public function show()
{
  $query=$this->mdl_widg_html->get('id');
  foreach ($query->result() as $row) {
   echo "<h3>".$row->body."</h3>";
  }
}


}
and this is the code of the module model(mdl_widg_html.php):

Code:
&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Mdl_widg_html extends CI_Model {

public function __construct()
{
  parent::__construct();
    
}

public function get($orderby)
  {
   $this->db->order_by($orderby);
   $query=$this->db->get('widg_html');
   return $query;
  }

}


and this is how I call the module in the view:
Code:
&lt;?php
echo Modules::run('widg_html/show') ;
?&gt;

Quote:A PHP Error was encountered

Severity: Notice

Message: Undefined property: Widg_html::$mdl_widg_html

Filename: controllers/widg_html.php

Line Number: 19


Fatal error: Call to a member function get() on a non-object in C:\xampp\htdocs\application\modules\widg_html\controllers\widg_html.php on line 19

Please can some Help me?
Thanks in advance

El Forum

[eluser]Harold Villacorte[/eluser]
It looks like a typo. Module controllers should extend MX_Controller.

In the model make sure that the database class is loaded and try something like this maybe:
Code:
$query = $this->db
    ->order_by($orderby)
    ->get('widg_html');
return ($query->num_rows() > 0) ? $query : FALSE;