Welcome Guest, Not a member yet? Register   Sign In
Problem in routing

(This post was last modified: 12-16-2019, 06:01 PM by Dedov_Evgeniy.)

Created a folder "Modules" with modules in the root ...
In file autoload.php
PHP Code:
$psr4 = [
'Config'      => APPPATH  'Config',
APP_NAMESPACE => APPPATH,                // For custom namespace
'App'         => APPPATH,                // To ensure filters, etc still found,
'Modules'     => ROOTPATH 'Modules',

structure in the module folder:
   - Config
   - Controllers
   - Models
   - Libraries
create controller: ContentAdminController
PHP Code:
namespace Modules\Content\Controllers;

// use CodeIgniter\Controller;

class ContentAdminController extends \CodeIgniter\Controller
    public function index()

add route:
PHP Code:
$routes->add('admin''ContentAdminController::index', ['namespace' => 'Modules\Content\Controllers']); 
url is work!

add route:
PHP Code:
$routes->add('admin/(:any)''$1::index', ['namespace' => 'Modules\Content\Controllers']); 
url is not work!

Help, why the class does not work dynamically? thanks

Why, no one will help?

(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 :: (optionalcontroller method \ (for different queries) $

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.

PHP Code:

-> ?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
         public function 
index(string $any) {
             echo `
Any segment: {$any}`;

I would change this world, but God doesn't give me the source.

PHP Code:
$1 - Controller
$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 )

Theme © iAndrew 2016 - Forum software by © MyBB