CodeIgniter Forums
Module view file showing invalid - 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: Module view file showing invalid (/showthread.php?tid=79026)



Module view file showing invalid - ciddict - 04-10-2021

I've added the module folder in ...\app\Config\Autoload.php


Quote:public $psr4 = [
          APP_NAMESPACE => APPPATH, // For custom app namespace
          'Config'      => APPPATH . 'Config',
          'Blog'      => ROOTPATH . 'example/blog',
];



My directory:


Quote:/Home directory of main project folder
/example
    /Blog
        /Config
            /Routes.php
        /Controllers            
            /Blog.php
        /Views
           /show_blog.php


Routes.php


PHP Code:
namespace Config;

// Create a new instance of our RouteCollection class.
$routes Services::routes();

$routes->get('blog''blog::index', ['namespace' => 'Blog\Controllers']); 

Blog.php


PHP Code:
namespace Blog\Controllers;

class 
Blog extends \CodeIgniter\Controller {

    function index() { 
        echo view('Example\Blog\Views\show_blog');
    }




After running my_domain/index.php/blog, it's showing this error:

Quote:CodeIgniter\View\Exceptions\ViewException

Invalid file: Example\Blog\Views\show_blog.php


Where I'm wrong? Looking for help. 
Thanks in advance.


RE: Module view file showing invalid - davis.lasis - 04-10-2021

i have not replicated and tested, but by the looks you should change folders and paths names with capital letters to make exact path matches

/example => /Example

public $psr4 = [
APP_NAMESPACE => APPPATH, // For custom app namespace
'Config' => APPPATH . 'Config',
'Blog' => ROOTPATH . 'Example/Blog',
];

$routes->get('blog', 'Blog::index', ['namespace' => 'Blog\Controllers']);


RE: Module view file showing invalid - paulbalandan - 04-10-2021

You do not have an `Example` namespace. It is actually `Blog`. So you should use that instead.
PHP Code:
function index() { 
    echo 
view('Blog\Views\show_blog');




RE: Module view file showing invalid - ciddict - 04-10-2021

@paulbalandan, it worked. Thank you so much.