I’ve added the module folder in …appConfigAutoload.php
public $psr4 = [ APP_NAMESPACE => APPPATH, // For custom app namespace 'Config' => APPPATH . 'Config', 'Blog' => ROOTPATH . 'example/blog', ];
My directory:
/Home directory of main project folder /example /Blog /Config /Routes.php /Controllers /Blog.php /Views /show_blog.php
Routes.php
namespace Config; // Create a new instance of our RouteCollection class. $routes = Services::routes(); $routes->get('blog', 'blog::index', ['namespace' => 'BlogControllers']);
Blog.php
namespace BlogControllers; class Blog extends CodeIgniterController { function index() { echo view('ExampleBlogViewsshow_blog'); } }
After running my_domain/index.php/blog, it’s showing this error:
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.
namespace BlogControllers; class Blog extends CodeIgniterController { function index() { echo view('BlogViewsshow_blog'); } }
Credit: CI Forum