CodeIgniter Forums
HMVC and db - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: HMVC and db (/showthread.php?tid=51893)



HMVC and db - El Forum - 05-22-2012

[eluser]riskk[/eluser]
I installed the codeigniter HMVC plugin and it's working fine for me but when I try to load method of module from other module I get the error

Here is my code:

Module billet:
Code:
class getcombo extends CI_Controller {
  public function  __construct()
  {
      parent::__construct();
  }

  public function index()
  {
      
  }

  public function semester()
  {                        
      parent :: StartAdmin();
      table_id = $this->db->select('table_id')->from('sys_tables')->where('table', 1)->get()->row()->table_id;

      return table_id;
  }
}

Module journal:
Code:
class journal extends MY_Controller {
  public function  __construct()
  {
      parent::__construct();
  }

  public function index()
  {
      parent :: StartAdmin();

      $this->load->module('billet/getcombo')->semester();
      return $this->getcombo->semester();
  }
}

And error
Code:
A PHP Error was encountered

Severity: Notice

Message: Undefined property: getcombo::$db

Filename: controllers/getcombo.php

Line Number: 30
Fatal error: Call to a member function select() on a non-object in /var/www/site.com/application/modules/billet/controllers/getcombo.php

The problem occur when I use
Code:
table_id = $this->db->select('table_id')->from('sys_tables')->where('table', 1)->get()->row()->table_id;
If load method directly it`s work fine

How to fix this problem.


HMVC and db - El Forum - 05-22-2012

[eluser]weboap[/eluser]
try
Code:
return modules::run(billet/getcombo/semester);

and btw
parent :: StartAdmin();??????


HMVC and db - El Forum - 05-22-2012

[eluser]riskk[/eluser]
same error
return modules::run(billet/getcombo/semester);

The problem occur when I use select to DB



parent :: StartAdmin() is method of base controller.


HMVC and db - El Forum - 05-22-2012

[eluser]weboap[/eluser]
sorry! that was not related.
when you place
Code:
table_id = $this->db->select('table_id')->from('sys_tables')->where('table', 1)->get()->row()->table_id;
in journal what happen?


HMVC and db - El Forum - 05-22-2012

[eluser]qpixo[/eluser]
[quote author="riskk" date="1337688069"]I installed the codeigniter HMVC plugin and it's working fine for me but when I try to load method of module from other module I get the error

Here is my code:

Module billet:
Code:
class getcombo extends CI_Controller {
  public function  __construct()
  {
      parent::__construct();
  }

  public function index()
  {
      
  }

  public function semester()
  {                        
      parent :: StartAdmin();
      table_id = $this->db->select('table_id')->from('sys_tables')->where('table', 1)->get()->row()->table_id;

      return table_id;
  }
}

Module journal:
Code:
class journal extends MY_Controller {
  public function  __construct()
  {
      parent::__construct();
  }

  public function index()
  {
      parent :: StartAdmin();

      $this->load->module('billet/getcombo')->semester();
      return $this->getcombo->semester();
  }
}

And error
Code:
A PHP Error was encountered

Severity: Notice

Message: Undefined property: getcombo::$db

Filename: controllers/getcombo.php

Line Number: 30
Fatal error: Call to a member function select() on a non-object in /var/www/site.com/application/modules/billet/controllers/getcombo.php

The problem occur when I use
Code:
table_id = $this->db->select('table_id')->from('sys_tables')->where('table', 1)->get()->row()->table_id;
If load method directly it`s work fine

How to fix this problem.[/quote]

Why did you do a request DB in a Controller? Any reasons?
You're not applied the basic concept of MVC here...

Secondly with HMVC when calling others modules, you should only use modules::run();



HMVC and db - El Forum - 05-22-2012

[eluser]weboap[/eluser]
also , if you are using the HMVC extension your controllers should be extended to MX_Controller unless you have a common class in MY_Cntroller and your controllers extended to it and it been extended in turn to MX_Controller.


HMVC and db - El Forum - 05-22-2012

[eluser]InsiteFX[/eluser]
Code:
parent :: StartAdmin();

// should be
$this->StartAdmin();



HMVC and db - El Forum - 05-22-2012

[eluser]riskk[/eluser]
[quote author="weboap" date="1337715775"]also , if you are using the HMVC extension your controllers should be extended to MX_Controller unless you have a common class in MY_Cntroller and your controllers extended to it and it been extended in turn to MX_Controller.[/quote]

Thank you!!! The problem was with the MX_Controller.