Problem in routing |
Hello.
Created a folder "Modules" with modules in the root ... In file autoload.php PHP Code: $psr4 = [ structure in the module folder: Content - Config - Controllers - Models - Libraries ... ... create controller: ContentAdminController PHP Code: namespace Modules\Content\Controllers; add route: PHP Code: $routes->add('admin', 'ContentAdminController::index', ['namespace' => 'Modules\Content\Controllers']); http://name_site.ru/admin add route: PHP Code: $routes->add('admin/(:any)', '$1::index', ['namespace' => 'Modules\Content\Controllers']); http://name_site.ru/admin/ContentAdminController Help, why the class does not work dynamically? thanks
12-23-2019, 02:44 PM
(This post was last modified: 12-23-2019, 03:12 PM by Digital_Wolf. Edit Reason: give examples. )
It must be:
PHP Code: (required*) controller class specified :: (optional) controller method \ (for different queries) $1 you can't use $n as a method placeholder or controller class itself. in General it's something like requests made after the sign "?" in the address bar. Example: PHP Code: https://example.com/controller/method/?other-query -> ?other-query it is substituted in a sign "$" and that your site understood that to catch in requests and that to pass by, it is necessary to use "placeholders". In Routes.php PHP Code: $routes->add('admin/(:any)', 'ContentAdminController::index/$1'); In ContentAdminController.php PHP Code: class ContentAdminController extends Controller I would change this world, but God doesn't give me the source.
PHP Code: $routes->add('admin/([a-z0-9+])/(:any)', '$1::index/$2'); $2 - Method So is it impossible?
there is no, so no one makes, I higher already led example the right use...
"$1" is essentially similar to get requests, that is, $_GET, but usually this placeholder is used together with models and database, depending on what gets into this placeholder, it will be derived from the database. I would change this world, but God doesn't give me the source.
You also need to namespace the Content folder.
PHP Code: 'Modules\Content' => ROOTPATH . 'Modules\Content', 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 |