- Seme Framework
- version 4.0.3
- Requirements
- Download & Install
- Configuration
- Tutorials
- URI Routing
- Constants
- Global Variables
- Model
- View
- Controller
- cdn_url
- config
- constructor
- getAdditional
- getAdditionalBefore
- getAdditionalAfter
- getAuthor
- getCanonical
- getContentLanguage
- getDescription
- getIcon
- getJsContent
- getJsFooter
- getJsReady
- getKey
- getKeyword
- getLang
- getRobots
- getShortcutIcon
- getThemeElement
- getTitle
- input
- lib
- load
- loadCss
- loadLayout
- putThemeContent
- putJsContent
- putJsFooter
- putJsReady
- render
- resetThemeContent
- session
- setAuthor
- setCanonical
- setContentLanguage
- setDescription
- setIcon
- setKey
- setKeyword
- setLang
- setShortcutIcon
- setTheme
- setTitle
- Library
- CLI (command line interface)
- Core
- Issue
- Deployment
Routes Configuration
Typically there is a one-to-one relationship between a URL string and its corresponding controller class/method. The segments in a URI normally follow this pattern:
example.com/class/method/id/
In some instances, however, you may want to remap this relationship so that a different class/function can be called instead of the one corresponding to the URL.
For example, lets say you want your URLs to have this prototype:
- example.com/product/1/
- example.com/product/2/
- example.com/product/3/
- example.com/product/4/
Normally the second segment of the URL is reserved for the function name, but in the example above it instead has a product ID. To overcome this, Seme Framework allows you to remap the URI handler.
Setting custom URI Routing
Routing rules are defined in your app/config/
. You can set this routing applied into production, staging, or development depend on your requirements.
On each configuration files, Seme Framework has created the commented section for rewriting URI in the routing section.
And then if you opened the configuration file, you'll see an array called $routes
that permits you to specify your own routing criteria. Routes can either be specified using wildcards
Wildcards
A typical wildcard route might look something like this:
$routes['product/:num'] = "catalog/product_lookup";
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.
You can match literal values or you can use two wildcard types:
(:num)
will match a segment containing only numbers.(:any)
will match a segment containing any character.
Examples Configuration
Here are a few URI - Controller route remapping configuration.
$routes['produk'] = "products";
A URL containing the word "produk" in the first segment will be remapped to the "products" class.
$routes['produk/ojan'] = "products/detail/15";
A URL containing the segments produk/ojan will be remapped to the "products" class and the "detail" method. The ID will be set to "15".
$routes['product/(:any)'] = "catalog/product_lookup";
A URL with "product" as the first segment, and anything in the second will be remapped to the "catalog" class and the "product_lookup" method.
$routes['product/(:num)'] = "catalog/product_lookup_by_id/$1";
A URL with "product" as the first segment, and a number in the second will be remapped to the "catalog" class and the "product_lookup_by_id" method passing in the match as a variable to the function.
Reserved Routes
There are two reserved routes:
$routes['home'] = 'home';
This route indicates which controller class should be loaded if the URI contains no data, which will be the case when people load your root URL. In the above example, the "welcome" class would be loaded. You are encouraged to always have a default route otherwise a 404 page will appear by default.
$routes['notfound'] = 'notfound';
This route indicates which controller class should be loaded if the requested controller is not found. By default it will executed app/controller/notfound.php
. You can change it if necessary.
Another reserved route is admin secret route. Please refer to this docs for using admin secret routing.