CodeIgniter Forums
problem with routes in Code Modules - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forum-28.html)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forum-30.html)
+--- Thread: problem with routes in Code Modules (/thread-75726.html)



problem with routes in Code Modules - midav - 03-10-2020

hello to everyone according to the instructions in the Code Modules documentation

https://codeigniter4.github.io/userguide/general/modules.html

but for some reason routes do not work in modules
here is my code

http://prntscr.com/re8f6h

http://prntscr.com/re8foi

http://prntscr.com/re8fwn

http://prntscr.com/re8g2h
and when I try to go to the admin panel, I get the following.

http://prntscr.com/re8guf


RE: problem with routes in Code Modules - InsiteFX - 03-10-2020

Try this one it works for me, the way you have your group you need to call it like admin/admin

this way you can call it admin and it will go to index method.

PHP Code:
<?php

/**
 * Insitefx/Admin: routes file.
 */

$routes->group('', ['namespace' => 'Insitefx\Admin\Controllers'], function($routes)
{
    $routes->get('admin''Admin::index', ['as' => 'admin']);
    $routes->get('admin/(:any)''Admin::view/$1');

    //$routes->get('dashboard', 'Admin::dashboard', ['as' => 'dashboard']);

}); 

See the group how I left the first field null ''

The bottom one that's remarked out is for the Admin Dashboard which does work using the route->to in html.


RE: problem with routes in Code Modules - midav - 03-10-2020

(03-10-2020, 08:10 AM)InsiteFX Wrote: Try this one it works for me, the way you have your group you need to call it like admin/admin

this way you can call it admin and it will go to index method.

PHP Code:
<?php

/**
 * Insitefx/Admin: routes file.
 */

$routes->group('', ['namespace' => 'Insitefx\Admin\Controllers'], function($routes)
{
    $routes->get('admin''Admin::index', ['as' => 'admin']);
    $routes->get('admin/(:any)''Admin::view/$1');

    //$routes->get('dashboard', 'Admin::dashboard', ['as' => 'dashboard']);

}); 

See the group how I left the first field null ''

The bottom one that's remarked out is for the Admin Dashboard which does work using the route->to in html.
it didn’t help, I see so far the very first version of the framework has many shortcomings. I set everything up according to the documentation and it didn’t help that I dropped it, but if I transfer it to the app / Config / routes.php folder, then my first option and yours work there.


RE: problem with routes in Code Modules - kilishan - 03-10-2020

The route has to point to the Admin folder for that layout, so:

PHP Code:
'Modules\Admin' => APPPATH .'/Modules/Admin'

This quote from that page in the user guide is the crucial bit, here:

Quote:When at the acme namespace above, we would need to make one small adjustment to make it so the files could be found: each “module” within the namespace would have to have it’s own namespace defined there. Acme would be changed to Acme\Blog. Once your module folder has been defined, the discover process would look for a Routes file, for example, at /acme/Blog/Config/Routes.php, just as if it was another application.



RE: problem with routes in Code Modules - midav - 03-10-2020

(03-10-2020, 10:28 AM)kilishan Wrote: The route has to point to the Admin folder for that layout, so:

PHP Code:
    'Modules\Admin' => APPPATH .'/Modules/Admin'

This quote from that page in the user guide is the crucial bit, here:

Quote:When at the acme namespace above, we would need to make one small adjustment to make it so the files could be found: each “module” within the namespace would have to have it’s own namespace defined there. Acme would be changed to Acme\Blog. Once your module folder has been defined, the discover process would look for a Routes file, for example, at /acme/Blog/Config/Routes.php, just as if it was another application.
ok, the new documentation showed how to write to the autoloader and it was said that it will search in folders, which means that the example is not shown correctly in the documentation.


RE: problem with routes in Code Modules - kilishan - 03-10-2020

Sorry if that was misleading. It will search within each namespace for the standard app folders, like Config, Models, etc), but it doesn't handle what you're trying to do here and scan more than one level deep. It will also search within Composer's psr4 namespaces in the same manner.


RE: problem with routes in Code Modules - tmtuan - 03-12-2020

i got them same problem too, my module folder is: https://s3.upanh.pro/2020/03/10/ci4.png i do as the same document said and my custom routes.php in acp/blog/config can not loaded. when i move the route code to app/config/routes.php i work fine.

how can i auto load the routes.php in acp/blog/config?


RE: problem with routes in Code Modules - InsiteFX - 03-13-2020

PHP Code:
// namespace acp/Blog

$psr4 = [
    'App'         => APPPATH,                     // To ensure filters, etc still found,
    APP_NAMESPACE => APPPATH,                     // For custom namespace
    'Config'      => APPPATH 'Config',          // Config namespace
    'acp\Blog'    => ROOTPATH.'acp\Blog',         // Acp Blog module
];