• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Routes Configuration

#1
What can be the cause of non-working paths by default.

in my: ..\application\Config\Routes
PHP Code:
$routes->setDefaultNamespace('Modules\Test\Controllers'); // $psr4 in autoload 'Modules\Test' => ROOTPATH.'modules/Test'
$routes->setDefaultController('Test');
$routes->setDefaultMethod('index'); 

in my controller: ..\modules\Test\Controllers\Test
PHP Code:
<?php namespace Modules\Test\Controllers;
class 
Test extends \CodeIgniter\Controller {
 
 public function index() {
 
   echo 'Ok!';
 
 }

When I was referring along the way, example.com received a response:

Controller or its method is not found: Modules\Test\Controllers\\\Test::index

The CodeIgniter4 User Guide says that: 

Quote:When a user visits the root of your site (i.e. example.com) the controller to use is determined by the value set by the setDefaultController() method, unless a route exists for it explicitly. The default value for this is Home which matches the controller at /application/Controllers/Home.php:

Worked Only an explicit indication:
PHP Code:
$routes->add('/''Test :: index'); // if Namespace 'App\Controllers' controller in \application\Controllers.
// OR if use group in \modules\Test\Config
$routes->group('test', ['namespace' => 'Modules\Test\Controllers'], function($routes)
{
$routes->get('/''Test::index'); 

Please show an example or tell me what's wrong, thanks!
Reply

#2
application/Config/Routes.php

set true discoverLocal

$routes->discoverLocal(true);
Reply

#3
(09-11-2018, 10:20 PM)dannywebdev Wrote: application/Config/Routes.php

set true discoverLocal

$routes->discoverLocal(true);

This allows you to search for routes for the code modules... As you can see, I already use it "modules\Test\Controllers\Test"
But I'm interested in setDefaultController(), which should be displayed when accessing a domain or a path not found. But this for some reason does not happen, not from the main application directory not from the created one. Such a feeling that no one has yet used this =)
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


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