Welcome Guest, Not a member yet? Register   Sign In
Help understanding routes
#1

Hi,

I am currently messing round with CI4 and I am having issue with understanding the routing.

I have a controller that I just randomly made:

PHP Code:
<?php

namespace App\Controllers;

use 
CodeIgniter\Controller;

class 
Login extends BaseController {
    
     
public function index() {
         
        
        
return view('welcome_message');
    }
    


now if I direct to login it works just fine without a line in routes.  if I add a route like so:

PHP Code:
$routes->get('admin''Login::index'); 


If I now go to /admin then it work and shows me login.  The issue is then if I move Login.php controller into a folder called admin in the controllers folder and change the route to:

PHP Code:
$routes->get('admin''admin/Login::index');

or 

$routes->get('admin''admin\Login::index'); 

I get:


Quote:Controller or its method is not found: \App\Controllers\admin\Login::index


and I cannot for the life of me figure out why this doesn't work.  Can anyone enlighten me on why this isn't working please?

Thanks,

Doomie
Reply
#2

Update your namespace to this:

namespace App\Controllers\Admin;

and move the Login file to the Admin folder.
Reply
#3

Thank you for that. I was too focused on the routing that I didn't look at the whole code.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB