Search code examples
phpcodeigniter-4

How can i access my controller located in "folder_name/controller_name" in codeigniter 4?


My Master controller located in "admin" folder. View image here

namespace App\Controllers\admin;
use CodeIgniter\Controller;
class Master extends Controller
{
function __construct(){
helper('url');
}
public function index()
{
$data["content"]="view_home";
echo view('template/template', $data);
}
}

In my Routes.php i added this

$routes->get('admin/master','Master::index',['namespace','App\Controllers\admin']);

when i access the page in the browser i get this error

404 - File Not Found Controller or its method is not found: {0}::{1}

What am i missing?


Solution

  • My silly mistake when setting up the route. I've put a "," instead of "=>". See the correct route below.

    $routes->get('admin/master','Master::index',['namespace' => 'App\Controllers\admin']);