hmvc Message: Undefined property: CI::$Templates code igniter

4.1k views Asked by At

Hi am watching this video https://www.youtube.com/watch?v=DS0GeknUkds for setting up my hmvc templates. i am already trying to call other modules but i got the error

Severity: Notice

Message: Undefined property: CI::$Templates

Filename: MX/Controller.php

Line Number: 59

i have this templates folder with a controller file Templates.php

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Templates extends MY_Controller{

    public function views($data = NULL){

        $this->load->view('templates/one_view');
    }
}

?>

this perfectly works if i directly called it. but the problem is on my login module.(http://localhost/ci_hmvc/index.php/login/index) i get the error,

Message: Undefined property: CI::$Templates

Filename: MX/Controller.php

Line Number: 59 

and

Severity: Error

Message: Call to a member function views() on null

Filename: controllers/Login.php

Line Number: 10

my controller is,

Login.php

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Login extends MY_Controller{


    public function index(){

        $data['content_view'] = 'login/login_view';
        $this->Templates->views($data);

    }
}

?>

how can i resolve this? is there is a problem with the hmvc setting ? or what?

p.s

i extended it to MY_Controllers because i have this file,

MY_Controller.php on my core folder..

<?php

class MY_Controller extends MX_Controller {

    function __contsruct()
    {
        parent::__construct();
        $this->load->module('Templates');
    }

}

?> 

thanks

2

There are 2 answers

1
Chris Otaalo On

In My_Controller change

function __contsruct 

to

function __construct()
0
Taufik Arief Widodo On

Have you a set or adding module path? If not yet. You can set your application/config/config.php like this

$config['modules_locations'] = array(
    APPPATH.'modules/' => '../modules/',
);

And your login.php change

public function index(){

        $data['content_view'] = 'login/login_view';
        $this->Templates->views($data);

    }

To

public function index(){

        $data['content_view'] = 'login/login_view';
        $this->templates->views($data);

    }