• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem in routing

#1
Hello.
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:
Content
   - Config
   - Controllers
   - Models
   - Libraries
   ...
   ...
create controller: ContentAdminController
PHP Code:
namespace Modules\Content\Controllers;

// use CodeIgniter\Controller;

class ContentAdminController extends \CodeIgniter\Controller
{
    public function index()
    {
    echo 
123;
    }


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

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

Help, why the class does not work dynamically? thanks
Reply

#2
Why, no one will help?
Reply

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

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

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

#4
PHP Code:
$routes->add('admin/([a-z0-9+])/(:any)''$1::index/$2'); 
$1 - Controller
$2 - Method

So is it impossible?
Reply

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

#6
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 )
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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