Search code examples
phpcodeigniterhmvc

Unable to load page with codeigniter


On my codeigniter HMVC project. When I try to run my first isset statement in modules foreach section. If I uncomment the code below then, fire fox loads page error The connection was reset.

But if I comment out the code like below the page loads fine very strange.

//if (isset($part[0]) && $this->setting->get($part[0] . '_status')) {
//  $data['modules'][] = Modules::run('catalog/module/'.$part[0].'/index');
//}

For some reason does not like using isset($part[0])

How code works

  • $part[0] it returns the module name example category
  • $part[1] it returns the module number example 66 category.66
  • $this->setting->get($part[0] . '_status') returns either 1 if enabled or 0 if disabled.

What could be the cause of page not loading when I uncomment the code above. Any suggestions

Controller

<?php

class Column_left extends MX_Controller {

    public function index() {
        $this->load->model('catalog/extension/model_extension_extension');
        $this->load->model('catalog/design/model_design_layout');

        $route = $this->uri->segment(1).'/'.$this->uri->segment(2);

        // $route outputs like pages/category

        $layout_id = 0;

        if (!$layout_id) {
            $layout_id = $this->model_design_layout->get_layout($route);
        }

        if (!$layout_id) {
            // Setting library autoloaded
            $layout_id = $this->setting->get('config_layout_id'); 
        }

        $data['modules'] = array();

        $modules = $this->model_design_layout->get_layout_modules($layout_id, 'column_left');

        foreach ($modules as $module) {
            $part = explode('.', $module['code']);

            echo $part[0];

            // Setting library autoloaded
            if (isset($part[0]) && $this->setting->get($part[0] . '_status')) {
                $data['modules'][] = Modules::run('catalog/module/'.$part[0].'/index');
            }

            if (isset($part[1])) {
                $setting_info = $this->model_extension_module->get_module($part[1]);

                if ($setting_info && $setting_info['status']) {
                    $data['modules'][] = Modules::run('catalog/module/'.$part[0].'/index', $setting_info);
                }
            }
        }

        // Setting library autoloaded
        if (file_exists(DIR_TEMPLATE .$this->setting->get('config_template'). '/template/common/column_left_view.php')) {
            $this->load->view('theme/'.$this->setting->get('config_template').'/template/common/column_left_view', $data);
        } else {
            $this->load->view('theme/default/template/common/column_left_view', $data);
        }
    }
}

View

<?php if ($modules) { ?>
<column id="column-left" class="col-sm-3 hidden-xs">
  <?php foreach ($modules as $module) { ?>
  <?php echo $module; ?>
  <?php } ?>
</column>
<?php } ?>

Solution

  • After working on it all after noon, was able to find the cause of the issue.

    In my catalog modules folder I had 2 controllers named the same in different folders, catalog/category & module/category. Even though they were in different folders one was over riding other and causing page load error on fire fox.

    How I solved problem. By renaming the controller in subfolder catalog to categories I refreshed page and then works.

    I also cleaned up code here.

    <?php
    
    class Column_left extends MX_Controller {
    
    public function index() {
        $this->load->model('catalog/design/model_design_layout');
    
        $route = $this->uri->segment(1).'/'.$this->uri->segment(2);
    
        $layout_id = 0;
    
        if (!$layout_id) {
            $layout_id = $this->model_design_layout->get_layout($route);    
        }
    
        if (!$layout_id) {
            $layout_id = $this->setting->get('config_layout_id'); 
        }
    
        $data['modules'] = array();
    
        $results = $this->model_design_layout->get_layout_modules($layout_id);
    
        foreach ($results as $result) {
            $part = explode('.', $result['code']);
    
            if (isset($part[0]) && $this->setting->get($part[0] . '_status')) {
                $data['modules'][] = Modules::run('catalog/module/'.$part[0].'/index');
            }
    
            if (isset($part[1])) {
    
               $this->load->model('catalog/extension/model_extension_module');
    
                $setting_info = $this->model_extension_module->get_module($part[1]);
                if ($setting_info && $setting_info['status']) {
                    $data['modules'][] = Modules::run('catalog/module/'.$part[0].'/index', $setting_info);
                }
            }
        }
    
        $this->load->view('theme/default/template/common/column_left_view', $data);
    }
    }