• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
problem with routes in Code Modules

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

https://codeigniter4.github.io/userguide...dules.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
Reply

#2
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.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#3
(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.
Reply

#4
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.
Support Development  • Practical CodeIgniter 3  •
Myth:AuthVulcan - CLI Tools for CI4
Reply

#5
(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.
Reply

#6
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.
Support Development  • Practical CodeIgniter 3  •
Myth:AuthVulcan - CLI Tools for CI4
Reply

#7
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?
Reply

#8
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
]; 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.