CodeIgniter Forums
HMVC not working trying to show view partial in CI 3.1.4 - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: External Resources (https://forum.codeigniter.com/forumdisplay.php?fid=7)
+--- Forum: Addins (https://forum.codeigniter.com/forumdisplay.php?fid=13)
+--- Thread: HMVC not working trying to show view partial in CI 3.1.4 (/showthread.php?tid=68389)



HMVC not working trying to show view partial in CI 3.1.4 - ivanblue21 - 07-04-2017

Hello, I started using HMVC today (https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc) and I've got to put the code to work as a module modifying MX_Loader (there was a missing function so I read), but when I tried to show the module as a view partial I get this error "Fatal error: Cannot redeclare class CI in C:\Datos\www\gastronegocios\application\third_party\MX\Base.php on line 57". This is my code:

Module Controller
PHP Code:
class Ivanblue extends MX_Controller {
 
  function __construct()
 
  {
 
     parent::__construct();
 
     date_default_timezone_set("America/Asuncion");

 
     $this->load->helper("url");
 
  }

 
  public function index()
 
  {
 
     $this->load->view("ivanblue");
 
  }


Module View
Code:
<p>
  <strong>Testing HMVC in <em>CodeIgniter</em></strong>
</p>

When I go to the controller directly at "http://localhost/gastronegocios/ivanblue" it works perfectly, but when I try to use it as a view partial I get the error "Fatal error: Cannot redeclare class CI in C:\Datos\www\gastronegocios\application\third_party\MX\Base.php on line 57".

This is how I'm trying to show it as a view partial, inside a normal view:
Code:
html code...
<?php echo modules::run("ivanblue"); ?>
html code...

How can I get this working? Thanks in advance.


RE: HMVC not working trying to show view partial in CI 3.1.4 - ivanblue21 - 07-06-2017

Hello, I found the solution. It was that my Home controller also should extend MX_Controller, not just the controllers at the modules folder. This is a really useful feature to have.

Thanks!


RE: HMVC not working trying to show view partial in CI 3.1.4 - InsiteFX - 07-07-2017

The best way is to create a MY_Controller extending the MX_Controller
then extend all of your controllers from the MY_Controller.