Code module not setting up - 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: Code module not setting up (/showthread.php?tid=82851) Pages:
1
2
|
Code module not setting up - leafface - 08-28-2022 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? RE: Code module not setting up - iRedds - 08-28-2022 backslash -> \Modules\YtVideos\Controllers\Admin_YtVideos::index RE: Code module not setting up - leafface - 08-29-2022 (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? RE: Code module not setting up - kenjis - 08-29-2022 If you disable Auto-Discovery (of routing), the module's Routes.php is not loaded. See https://codeigniter4.github.io/CodeIgniter4/general/modules.html#auto-discoveryv RE: Code module not setting up - leafface - 08-29-2022 (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. RE: Code module not setting up - kenjis - 08-29-2022 Can you show your two Routes.php? What do you get when you run `spark routes`? RE: Code module not setting up - leafface - 08-30-2022 (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. RE: Code module not setting up - leafface - 08-30-2022 The view() function also cannot locate the module's view file, looks for the view in the \app\Views folder :/ RE: Code module not setting up - kenjis - 08-30-2022 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/CodeIgniter4/incoming/routing.html#route-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/CodeIgniter4/outgoing/views.html#namespaced-views RE: Code module not setting up - InsiteFX - 08-31-2022 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. |