CodeIgniter Forums
FrameworkException::forInvalidFile / CORS Issues - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forum-28.html)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forum-30.html)
+--- Thread: FrameworkException::forInvalidFile / CORS Issues (/thread-77313.html)



FrameworkException::forInvalidFile / CORS Issues - myo - 08-15-2020

Hi,

My site was working fine at local machine but when I uploaded to web host some of my views are not loading & I am getting following error:

Code:
CodeIgniter\Exceptions\FrameworkException::forInvalidFile

The concerned view is a modal in a separate view file which I load using js upon click of a button.

When I try to directly access that URI, I get WHOOPS page.: 

Whoops!

We seem to have hit a snag. Please try again later...


Any idea how to rectify it?


RE: FrameworkException::forInvalidFile / CORS Issues - InsiteFX - 08-15-2020

Turn on the debug bar to see what the error is then turn it off.

edit the env file in the root with index.php add

CI_ENVIRONMENT = developement

Then save the file as .env

when finished just remove the . off the begging of it.

Also look at your server error files.


RE: FrameworkException::forInvalidFile / CORS Issues - myo - 08-15-2020

Hi,

I did this & following are details:

CodeIgniter\View\Exceptions\ViewException
SYSTEMPATH/Exceptions/FrameworkException.php at line 17

Response Status    500 - Internal Server Error

log-2020-08-15.log
CRITICAL - 2020-08-15 16:22:52 --> Invalid file: my_view.php
#0 /system/View/View.php(228): CodeIgniter\Exceptions\FrameworkException::forInvalidFile('my...')
#1 /system/Common.php(1087): CodeIgniter\View\View->render('my...', Array, true)
#2 /app/Controllers/Mycontroller.php(147): view('my...', Array)
#3 /system/CodeIgniter.php(914): App\Controllers\Mycontroller->hello()
#4 /system/CodeIgniter.php(400): CodeIgniter\CodeIgniter->runController(Object(App\Controllers\Mycontroller))
#5 /system/CodeIgniter.php(308): CodeIgniter\CodeIgniter->handleRequest(NULL, Object(Config\Cache), false)
#6 /index.php(48): CodeIgniter\CodeIgniter->run()
#7 {main}


Same code is working perfectly at local machine.


RE: FrameworkException::forInvalidFile / CORS Issues - InsiteFX - 08-15-2020

That error line 17 is
SYSTEMPATH/Exceptions/FrameworkException.php at line 17
forEnabledZlibOutputCompression()

Check your php version it has to be 7.2.0+

500 is usually a server error but could be a programming error also.

For CORS errors you can try the below and add it to your htaccess file where index.php is:

Code:
# Add Font Types
AddType application/vnd.ms-fontobject .eot
AddType font/truetype .ttf
AddType font/opentype .otf
AddType font/opentype .woff
AddType font/opentype .woff2
AddType image/svg+xml .svg .svgz

<FilesMatch ".(eot|ttf|otf|woff|woff2|svg|svgz)">
    Header set Access-Control-Allow-Origin "http://www.your_website.com"
</FilesMatch>

Chang this to match your website "http://www.your_website.com"


RE: FrameworkException::forInvalidFile / CORS Issues - paulbalandan - 08-15-2020

If your zlib output compression is turned on, you must turn it off as it will interfere with output buffering.

Go to your php.ini and find the line zlib.output_compression. Replace the value to Off. Then restart your server.


RE: FrameworkException::forInvalidFile / CORS Issues - myo - 08-16-2020

Hi,

I dig into this and found that the "$this->loader->locateFile" is raising exception in System/View/View at line: 222
PHP Code:
if (! is_file($this->renderVars['file']))
{
$this->renderVars['file'] = $this->loader->locateFile($this->renderVars['view'], 'Views', empty($fileExt) ? 'php' $fileExt);


Here are values I collected here:
----------------------------------------------------------------------
$this->renderVars['view']:  R1/My/my_view.php
----------------------------------------------------------------------
$this->viewPath: /app/Config/../Views/
----------------------------------------------------------------------
$this->renderVars['file']: /app/Config/../Views/R1/My/my_view.php
----------------------------------------------------------------------
$this->loader->locateFile($this->renderVars['view']Result assigned at line 222 is BLANK which raises exception
----------------------------------------------------------------------


Still I am unable to conclude why its happening as its working at local machine? Why locateFile is unable to locate views? Do i need to change .htaccess. Following is what I have now:


IndexIgnore *

RewriteEngine on

RewriteCond %{REQUEST_URI} ^/system.*
RewriteRule ^(.*)$ index.php?/$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?/$1 [L]

# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php72” package as the default “PHP” programming language.
<IfModule mime_module>
  AddHandler application/x-httpd-ea-php72 .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit

# Add Font Types
AddType application/vnd.ms-fontobject .eot
AddType font/truetype .ttf
AddType font/opentype .otf
AddType font/opentype .woff
AddType font/opentype .woff2
AddType image/svg+xml .svg .svgz

<FilesMatch ".(eot|ttf|otf|woff|woff2|svg|svgz)">
    Header set Access-Control-Allow-Origin "http://www.your_website.com"
</FilesMatch>


Note: zlib output compression is turned off & I am using PHP 7.2


RE: FrameworkException::forInvalidFile / CORS Issues - InsiteFX - 08-16-2020

Check that view file and make sure that there are no extra space in the top.

Also please show the view file that is causing you the error would help a lot
in determining the cause of the Error.