Route File
Routes are responsible for responding to URL requests. Routing matches the URL to the pre-defined routes. Routes in miniCal are defined using the below example:
Controller/Method/Parameter/
- Controller -is mapped to the controller name that should respond to the URL.
- Method – is mapped to the method in the controller that should respond to the URI request.
- Parameter – this section is optional.
For defining route for extension go to the route.php filer under the config folder of your extension.
Here is an example for the route file.
$extension_route['list'] = 'show_booking/show_latest_bookings';
Use the $extension_route variable for routes, it's the same as CI routes.
$extension_route['list']
Here this list is the route name, the URL for this route will look like this "https://demo.minical.io/list"
Now, this route is bound with a controller and its method. In the above example, we can see that this list route is bound with show_booking controller and the method of show_booking controller is "show_latest_bookings".
A typical route with a might look something like this:
//Syntaxt
$extension_route['route_name/:num'] = 'contoller/method/$1';
//example
$extension_route['product/:num'] = 'catalog/product_lookup/$1';
In a route, the array key contains the URI to be matched, while the array value contains the destination it should be re-routed to. In the above example, if the literal word “product” is found in the first segment of the URL, and a number is found in the second segment, the “catalog” class and the “product_lookup” method are instead used.
(:num) will match a segment containing only numbers.
(:any) will match a segment containing any character (except for ‘/’, which is the segment delimiter).
You can send n-numbers of parameters with a route
$extension_route['route_one'] = 'controller/method';
$extension_route['route_two/(:any)'] = 'controller/method/$1';
$extension_route['route_three/(:any)/(:any)'] = 'controller/method/$1/$2';
$extension_route['route_four/(:any)/(:any)/(:any)'] = 'controller/method/$1/$2/3';
Here we have provided the list of basic URLs (CRUD operations)
Syntaxt | URL | Route | Controller | Method |
---|---|---|---|---|
$extension_route['/booking_list'] = 'bookinng_controller/index'; | /booking_list | $extension_route['/booking_list'] | bookinng_controller | index |
$extension_route['/booking/create'] = 'bookinng_controller/create'; | /booking/create | $extension_route['/booking/create'] | bookinng_controller | create |
$extension_route['/booking/edit/:id'] = 'bookinng_controller/edit'; | /booking/edit/id | $extension_route['/booking/edit/:id'] | bookinng_controller | edit |
$extension_route['/booking/delete/:id'] = 'bookinng_controller/delete'; | /booking/delete/id | $extension_route['/booking/delete/:id'] | bookinng_controller | delete |
Last modified 1yr ago