0

I am using codeigniter 4 with modules.I am getting error invalid file :Admin/valid_faq.php What is wrong in the view path? My Module structure is like below

app
 --modules
   -- Faq
      --controller
      --Models
      --Views
        --Admin
          --view_faq


    echo view('layout/header', $data);
    echo view('layout/sidebar');
    echo view('Admin/view_faq', $data);
    echo view('layout/footer');

I have gave the full path then also it doesn't work.

    echo view('App/Modules/Faq/Views/Admin/view_faq');
    echo view('Modules/Faq/Views/Admin/view_faq');

I have added to Autoload as well

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

When I checked the view file SYSTEMPATH\Common.php : 1121 — CodeIgniter\View\View->render ( arguments )

F:\xampp\htdocs\modularcms\app\Config/../Views/Modules/Faq/Views/Admin/view_faq.php

This is working

echo view('../Modules/Faq/Views/Admin/view_faq', $data);

my view directory in the paths

 public $viewDirectory = __DIR__ . '/../Views';

Error function

public static function renderer(string $viewPath = null, $config = null, bool $getShared = true)
{
    if ($getShared)
    {
        return static::getSharedInstance('renderer', $viewPath, $config);
    }

    if (is_null($config))
    {
        $config = new \Config\View();
    }

    if (is_null($viewPath))
    {
        $paths = config('Paths');

        $viewPath = $paths->viewDirectory;
    }

    return new \CodeIgniter\View\View($config, $viewPath, static::locator(), CI_DEBUG, static::logger());
}
5
  • That can be cause of 'sentence case' of file and path name. Commented Nov 1, 2020 at 12:57
  • I did not get. Can you explain Commented Nov 2, 2020 at 15:51
  • Is your view filename view_faq or view_faq.php or view_faq.html ? Commented Nov 6, 2020 at 7:43
  • it is view_faq in the view Commented Nov 6, 2020 at 8:10
  • Any solution for this? Commented Apr 10, 2021 at 11:10

2 Answers 2

1

I'm not clear about your modules directory. Let’s say you want to keep a simple Faq module that you can re-use between applications. You might create folder with name, faq, to store all of your modules within. You will put it right alongside your app directory in the main project root:

/faq        // modules directory
/app
/public
/system
/tests
/writable

Open app/Config/Autoload.php and add the Faq namespace to the psr4 array property:

$psr4 = [
    'Config'        => APPPATH . 'Config',
    APP_NAMESPACE   => APPPATH,                // For custom namespace
    'App'           => APPPATH,                // To ensure filters, etc still found,
    'Faq'          => ROOTPATH.'faq'
];

A common directory structure within a module will mimic the main application folder:

/faq
    /modules
        /Config
        /Controllers
        /Database
        /Helpers
        /Language
        /Libraries
        /Models
        /Views
            /Admin
               /view_faq

View:

echo view('Faq\Modules\Views\view_faq', $data);
Sign up to request clarification or add additional context in comments.

Comments

0

It's probably already too late, but maybe others - like me - are looking for it. The solution was there for me: Write the folder in the Views folder in lower case and put a double backslash behind it. So in your example:

echo view('Modules\Faq\Views\admin\\view_faq');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.