@@ -160,6 +160,7 @@ public function __construct(RouteCollectionInterface $routes)
160160 * @param string $uri
161161 *
162162 * @return mixed
163+ * @throws \CodeIgniter\Router\RedirectException
163164 */
164165 public function handle (string $ uri = null )
165166 {
@@ -192,7 +193,7 @@ public function handle(string $uri = null)
192193
193194 $ this ->autoRoute ($ uri );
194195
195- return $ this ->controller ;
196+ return $ this ->controllerName () ;
196197 }
197198
198199 //--------------------------------------------------------------------
@@ -216,7 +217,9 @@ public function getFilter()
216217 */
217218 public function controllerName ()
218219 {
219- return $ this ->controller ;
220+ return $ this ->translateURIDashes
221+ ? str_replace ('- ' , '_ ' , $ this ->controller )
222+ : $ this ->controller ;
220223 }
221224
222225 //--------------------------------------------------------------------
@@ -229,7 +232,9 @@ public function controllerName()
229232 */
230233 public function methodName (): string
231234 {
232- return $ this ->method ;
235+ return $ this ->translateURIDashes
236+ ? str_replace ('- ' , '_ ' , $ this ->method )
237+ : $ this ->method ;
233238 }
234239
235240 //--------------------------------------------------------------------
@@ -529,7 +534,7 @@ public function autoRoute(string $uri)
529534 }
530535
531536 // Load the file so that it's available for CodeIgniter.
532- $ file = APPPATH . 'Controllers/ ' . $ this ->directory . $ this ->controller . '.php ' ;
537+ $ file = APPPATH . 'Controllers/ ' . $ this ->directory . $ this ->controllerName () . '.php ' ;
533538 if (is_file ($ file ))
534539 {
535540 include_once $ file ;
@@ -539,7 +544,7 @@ public function autoRoute(string $uri)
539544 // We have to check for a length over 1, since by default it will be '\'
540545 if (strpos ($ this ->controller , '\\' ) === false && strlen ($ this ->collection ->getDefaultNamespace ()) > 1 )
541546 {
542- $ this ->controller = str_replace ('/ ' , '\\' , $ this ->collection ->getDefaultNamespace () . $ this ->directory . $ this ->controller );
547+ $ this ->controller = str_replace ('/ ' , '\\' , $ this ->collection ->getDefaultNamespace () . $ this ->directory . $ this ->controllerName () );
543548 }
544549 }
545550
@@ -620,15 +625,6 @@ protected function setRequest(array $segments = [])
620625 return ;
621626 }
622627
623- if ($ this ->translateURIDashes === true )
624- {
625- $ segments [0 ] = str_replace ('- ' , '_ ' , $ segments [0 ]);
626- if (isset ($ segments [1 ]))
627- {
628- $ segments [1 ] = str_replace ('- ' , '_ ' , $ segments [1 ]);
629- }
630- }
631-
632628 list ($ controller , $ method ) = array_pad (explode (':: ' , $ segments [0 ]), 2 , null );
633629
634630 $ this ->controller = $ controller ;
0 commit comments