php - I can't load any controller but the one with the module name in CodeIgniter HMVC -
so, i'm developing website in codeigniter 3 hmvc, , i've got following folder structture inside application folder:
core my_controller.php modules login controllers keep_logged.php login.php
so, my_controller (i'm using parent controllers):
<?php (defined('basepath')) or exit('no direct script access allowed'); class my_controller extends mx_controller { function __construct() { parent::__construct(); $this->load->module("template"); $this->load->module("login/keep_logged"); $this->keep_logged->cookie_authenticate(); $exceptions = array("login", "login/authenticate"); if ($this->session->user_id == null && !in_array(uri_string(), $exceptions)) { redirect("/login", "refresh"); } } }
and keep_logged.php
<?php class keep_logged extends my_controller { function __construct() { parent::__construct(); $this->load->model("login/login_model"); $this->load->helper("cookie"); } function cookie_authenticate() { if ($user = $this->login_model->check_login(get_cookie("user_email"), get_cookie("user_password"), true)) { $this->session->set_userdata(array( "user_id" => $user->user_id, "user_email" => $user->email, "user_name" => $user->name, "user_kind" => $user->kind )); } } }
my problem can't load keep_logged.php controller, though can load login.php (or controller same name it's module). how can fix ? errors every time.
a php error encountered
severity: notice
message: undefined property: ci::$keep_logged
filename: mx/controller.php
line number: 59
-
an uncaught exception encountered
type: error
message: call member function cookie_authenticate() on null
filename: d:\xampp\htdocs\cihmvc\application\core\my_controller.php
line number: 13
you try call method of child class in parent class. move cookie_authenticate()
method my_controller , call in $this->cookie_authenticate()
. don`t forget move staff keep_logged constructor my_controller constructor.
Comments
Post a Comment