Modules and Views |
CodeIgniter 4.1.1 PHP7.4.4
Cannot get module views to work: http://localhost/Airports/moduleTest results in: viewException: Invalid file: Bobk\airports\views\moduleTest.php This is the setup. I've created my namespace called 'Bobk' in app/Config/Autoload.php Code: // app/Config/Autoload.php In folder ROOTPATH/Bobk I have a module folder called 'airports' airports/controllers/Airports.php airports/models/Airport_model.php (not used to show problem) airports/views/moduleTest.php My airports/controllers/Airports.php file: Code: <?php namespace Bobk\Airports\controllers; // app\Config\routes.php Code: /* // ROOTPATH/Bobk/airports/views/moduleTest.php Code: <html> THE PROBLEM // system/View/View.php LINE:195 Code: if (! is_file($this->renderVars['file'])) This call to locateFile() has the $folder argument set to the literal string 'Views' This results in the resolved view path being: ROUTEPATH\Bobk\/Views/airports/views/moduleTest.php" (I've used ROUTEPATH to avoid having to type the complete path) Notice that this call to locateFile has placed </Views/> (the $folder argument) in between Bobk\ and airports. This is obviously an incorrect path and results in ViewException: Invalid file: Bobk\airports\views\moduleTest.php Note: locateFile() returns false if it can't locate the view file, NOT the offending path which is probably why the invalid file displayed on screen doesn't match. WHAT APPEARS TO WORK (but for how long ?) Edit system/View/View.php LINE:197 and replace 'Views' argument with an empty string '' Code: 197 $this->renderVars['file'] = $this->loader->locateFile($this->renderVars['view'], '', empty($fileExt) ? 'php' : $fileExt); Not advocating this as a real fix but haven't yet managed to find out why the 'Views' argument is there and what it is meant to achieve. Testing this modification with modules and with normal app controllers and views works. Must be a reason for 'Views' argument and I look forward to finding out from those wiser (more informed) than me. |
Messages In This Thread |
Modules and Views - by [email protected] - 03-29-2021, 11:28 AM
RE: Modules and Views - by [email protected] - 03-29-2021, 03:37 PM
RE: Modules and Views - by InsiteFX - 03-29-2021, 08:51 PM
RE: Modules and Views - by [email protected] - 03-30-2021, 06:50 AM
|