Code module not setting up |
Hello,
I'm trying to set up a code module following the steps in the user guide. 1) I added the module to the psr4 section of the Autoload.php: PHP Code: public $psr4 = [ 2) Then I tried to add a route to the module's Routes.php: PHP Code: namespace Config; This has no effect though, although the module's Routes.php gets loaded (error messages get thrown when something's wrong in it). When I put the above route definition in the default Routes.php, I get the following error message: Controller or its method is not found: \App\Controllers\Modules\YtVideos\Controllers\Admin_YtVideos::index As you see, it looks for a Modules namespace inside the \App\Controllers namespace, although the Modules\YtVideos namespace is supposed to be handled as a root namespace. What am I doing wrong? (08-28-2022, 02:49 PM)iRedds Wrote: backslash -> \Modules\YtVideos\Controllers\Admin_YtVideos::index Thanks. It was stupid of me not to think of that. (I relied too much on the user guide where there is no backslash.) The other problem I mentioned is that the module's Routes.php doesn't take effect even though it gets included. I can only set route definitions in the default Routes.php. What is wrong there?
If you disable Auto-Discovery (of routing), the module's Routes.php is not loaded.
See https://codeigniter4.github.io/CodeIgnit...discoveryv (08-29-2022, 05:14 AM)kenjis Wrote: If you disable Auto-Discovery (of routing), the module's Routes.php is not loaded. Auto discovery was already enabled in app/Config/Modules.php, still the module's route definition doesn't take effect. PHP Code: public $enabled = true; PHP Code: public $aliases = [ Also, if there's a syntax error in the module's Routes.php, the program throws the error message, which hints that it is included/discovered.
Can you show your two Routes.php?
What do you get when you run `spark routes`? (08-29-2022, 06:39 PM)kenjis Wrote: Can you show your two Routes.php? All right, here are the two files: \app\Config\Routes.php: PHP Code: <?php \modules\YtVideos\Config\Routes.php: PHP Code: <?php I don't have Spark unfortunately.
The view() function also cannot locate the module's view file, looks for the view in the \app\Views folder :/
If you installed CI4, you have `spark` in the project root folder.
$routes->get('(:any)', 'Pages::view/$1'); takes all the routes. See https://codeigniter4.github.io/CodeIgnit...e-priority (08-30-2022, 07:46 AM)leafface Wrote: The view() function also cannot locate the module's view file, looks for the view in the \app\Views folder :/ See https://codeigniter4.github.io/CodeIgnit...aced-views
He should not have the modules route in the main route file.
As for the view he needs to pass the full namespace with it. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
|
Welcome Guest, Not a member yet? Register Sign In |