Reputation: 1990
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());
}
Upvotes: 0
Views: 11282
Reputation: 1
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');
Upvotes: 0
Reputation: 133
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);
Upvotes: 1