Welcome Guest, Not a member yet? Register   Sign In
Module view file showing invalid
#1

(This post was last modified: 04-10-2021, 08:25 AM by ciddict.)

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.
Reply
#2

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']);
Reply
#3

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');

Reply
#4

@paulbalandan, it worked. Thank you so much.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB