Welcome Guest, Not a member yet? Register   Sign In
HMVC and db
#1

[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.
#2

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

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

[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.
#4

[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?
#5

[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();
#6

[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.
#7

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

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

[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.




Theme © iAndrew 2016 - Forum software by © MyBB