View Not Rendered Codeigniter HMVC

603 Views Asked by At

I am trying to make a CRUD Module in Codeigniter HMVC but I seem to be missing something in the process. Here is what I am facing.

I have a News Module which has a Manage function

function manage(){
        $grid = Modules::run('Crud/renderGrid', 'News' , 'News management');

    }

Render Grid Function

function renderGrid($module , $page_title){

        $data['page_title'] = $page_title; //Dynamic
        $data['module'] = $module; 
        $data['view_module'] = 'Crud';
        $data['displayfields'] = Modules::run($module.'/get_displayfields');
        $data['key'] = Modules::run($module.'/get_key');
        $data['rows'] = Modules::run($module.'/get' , $data['key']);
        $data['view_file'] = 'manage';

        $this->load->module('dashboard');
        $this->dashboard->show_dashboard($data);
    }

Here, the show_dashboard function just loads up a template layout with a desired view in it.

function show_dashboard($data = NULL){
        if($data == NULL){
            $data['view_file'] = "manage";
            $data['page_title'] = 'Sigma Web Solutions';
        }

        $this->load->module('templates');
        $this->templates->admin($data);
    }

Templates->admin

function admin($data){
        $this->load->view('admin' , $data);
    }

The View (omitting the header n Footer)

<?php
                if (!isset($view_file)) {
                    $view_file = "";
                }


                if (!isset($view_module)) {
                    $module = $this->uri->segment(1);
                }


                if (($view_module!="") && ($view_file!="")) {

                    $path = $view_module."/".$view_file;
                    $this->load->view($path);
                }


                ?>

Now, when I try the url news/manage, it gives me a blank page with no source code in it. But when I try something like

crud/renderGrid/news/sometitle/ it works just fine.

Kindly point out what did I miss here. Thanks.

Working Solution:

Thanks to wolf I added a route

$route['managenews']= 'crud/renderGrid/news/News';

And it works like charm. But why do I need a route here? Shouldn't it just work. And this means for every module I need to have 4 entries in my route file for the CRUD system to work. can anyone suggest a better method?

0

There are 0 best solutions below