I’ve added the module folder in …appConfigAutoload.php
JavaScript
x
public $psr4 = [
APP_NAMESPACE => APPPATH, // For custom app namespace
'Config' => APPPATH . 'Config',
'Blog' => ROOTPATH . 'example/blog',
];
My directory:
JavaScript
/Home directory of main project folder
/example
/Blog
/Config
/Routes.php
/Controllers
/Blog.php
/Views
/show_blog.php
Routes.php
JavaScript
namespace Config;
// Create a new instance of our RouteCollection class.
$routes = Services::routes();
$routes->get('blog', 'blog::index', ['namespace' => 'BlogControllers']);
Blog.php
JavaScript
namespace BlogControllers;
class Blog extends CodeIgniterController {
function index() {
echo view('ExampleBlogViewsshow_blog');
}
}
After running my_domain/index.php/blog, it’s showing this error:
JavaScript
CodeIgniterViewExceptionsViewException
Invalid file: ExampleBlogViewsshow_blog.php
Didn’t get any solution from this one: Codeigniter 4 View file invalid
Where am I wrong?
Advertisement
Answer
Changing Blog.php to this, worked for me.
JavaScript
namespace BlogControllers;
class Blog extends CodeIgniterController {
function index() {
echo view('BlogViewsshow_blog');
}
}
Credit: CI Forum