Problem with $this in child Class extend of MX_Controllers - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: Problem with $this in child Class extend of MX_Controllers (/showthread.php?tid=75386) |
Problem with $this in child Class extend of MX_Controllers - avidal - 01-31-2020 Hi! I am having an error with the $ this reserved variable in my daughter classes inherited from MX_Controllers. It is because the & get_intance () does not arrive completely. Can you help me find the error please. PHP Version: 7.2 Error: Fatal error: Uncaught Error: Using $this when not in object context in D:\Proyectos\OEFA\SGSA\application\modules\admin\controllers\login.php:14 Stack trace: #0 D:\Proyectos\OEFA\SGSA\application\third_party\MX\Controller.php(170): login::index() #1 D:\Proyectos\OEFA\SGSA\system\core\CodeIgniter.php(326): MX_Controller->_remap('index', Array) #2 D:\Proyectos\OEFA\SGSA\index.php(202): require_once('D:\\Proyectos\\OE...') #3 {main} thrown in D:\Proyectos\OEFA\SGSA\application\modules\admin\controllers\login.php on line 14 My Class: PHP Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); MX_Controller: PHP Code: <?php (defined('BASEPATH')) OR exit('No direct script access allowed'); Thanks- RE: Problem with $this in child Class extend of MX_Controllers - ajmeireles - 02-01-2020 As I can see the object $this->auth really isn't recognized by Login class. Where is this object, on Base.php? If this object is from other controller or lib I recommend create an lib or helper and subsequetly create a superglobal. On my latest project based on CI3 I have a superglobal ci that's instancied on BaseController, like this: PHP Code: class BaseController extends CI_Controller Then I can use $this->ci->panel to show "abc" where I want: controller or views. (it's necessary running Global with part of autoloader) RE: Problem with $this in child Class extend of MX_Controllers - InsiteFX - 02-01-2020 If this is just the downloaded version of HMVC then there are all kinds of fixes on the forum topics here. Do a forum search for HMVC. RE: Problem with $this in child Class extend of MX_Controllers - avidal - 02-01-2020 (02-01-2020, 04:14 AM)ajmeireles Wrote: As I can see the object $this->auth really isn't recognized by Login class. Where is this object, on Base.php? Thanks, but I don't want to replace all my classes and files that have $ this-> with $ this-> ci-> are many files. Why doesn't the father's constructor inherit? Any other solution? |