Extending BaseController gives error - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30) +--- Thread: Extending BaseController gives error (/showthread.php?tid=74252) |
Extending BaseController gives error - Ambroz - 09-03-2019 Hi. I'm trying to use some code from CI 3 and got a error, where I can't use the provided variables to load views by template. The error is just the site isn't loading. This is the code I would like to use in CI 4: PHP Code: <?php I've used the _viewData to load views by the template. One of my old, I mean CI 3, controllers: PHP Code: defined('BASEPATH') OR exit('No direct script access allowed'); The template code: PHP Code: <?=$header?> I really like this method of constructing the site, so could you help me make it work? Hope you will help me . Thanks a lot. RE: Extending BaseController gives error - jaddle - 09-26-2019 I'm just getting started with this myself, but I can say that a huge amount has changed from CI3 to CI4 - code for version 3 will rarely, if ever, work in the new version! I'm trying to update an old site, and I'm finding that basically everything has to be redone. Learning as I go! RE: Extending BaseController gives error - InsiteFX - 09-28-2019 CI 4 comes with a BaseController that is what you would use, think of the BaseController as the MY_Controller Add what you need add to the BaseController then extend all your other controllers from it. Oh, Do Not call the parent::__construct() there is no constructor in the Controller It uses an initController() method instead. ( RE: Extending BaseController gives error - Ambroz - 11-09-2019 Sorry for the late reply. I tryed using the initController in the BaseController to recreate what I had in CI3 but that doesn't work. Is it still possible to pass a view to a variable like in CI3? For example: PHP Code: $this->_viewData['header'] = view('parts/header', $this->_viewData, true); |