Skip to content

Instantly share code, notes, and snippets.

@prolongservices
Created June 13, 2020 21:18
Show Gist options
  • Select an option

  • Save prolongservices/b4717bf258da21517bdb5119cb6442b6 to your computer and use it in GitHub Desktop.

Select an option

Save prolongservices/b4717bf258da21517bdb5119cb6442b6 to your computer and use it in GitHub Desktop.
<?php namespace Config;
// Create a new instance of our RouteCollection class.
$routes = Services::routes(true);
// Load the system's routing file first, so that the app and ENVIRONMENT
// can override as needed.
if (file_exists(SYSTEMPATH . 'Config/Routes.php'))
{
require SYSTEMPATH . 'Config/Routes.php';
}
/**
* --------------------------------------------------------------------
* Router Setup
* --------------------------------------------------------------------
*/
$routes->setDefaultNamespace('App\Controllers');
$routes->setDefaultController('MyController');
$routes->setDefaultMethod('index');
$routes->setTranslateURIDashes(false);
$routes->set404Override(function() {
return view('404');
});
$routes->setAutoRoute(true);
/**
* --------------------------------------------------------------------
* Route Definitions
* --------------------------------------------------------------------
*/
// We get a performance increase by specifying the default
// route since we don't have to scan directories.
$routes->get('/', 'MyController::index');
$routes->add('hello', 'BuildResponse::show');
$routes->add('hi', 'BuildResponse::show/45');
$routes->add('hi/(:num)', 'BuildResponse::show/$1');
$routes->group('admin', function($routes){
$routes->group('user', function($routes) {
$routes->add('form', 'BuildResponse::show/45');
$routes->add('login', 'BuildResponse::loginForm');
});
});
$routes->post('login', 'BuildResponse::loginForm');
$routes->put('login', 'BuildResponse::loginForm');
$routes->delete('login', 'BuildResponse::deleteUser');
/**
* --------------------------------------------------------------------
* Additional Routing
* --------------------------------------------------------------------
*
* There will often be times that you need additional routing and you
* need to it be able to override any defaults in this file. Environment
* based routes is one such time. require() additional route files here
* to make that happen.
*
* You will have access to the $routes object within that file without
* needing to reload it.
*/
if (file_exists(APPPATH . 'Config/' . ENVIRONMENT . '/Routes.php'))
{
require APPPATH . 'Config/' . ENVIRONMENT . '/Routes.php';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment