namespace \webfiori\framework\router
class Router
Class Attributes Summary
Class Methods Summary
Class Attributes Details
Class Methods Details
Parameters:
- array $options An associative array of options. Available options are:
- path: The path part of the URI. For example, if the requested URI is 'http://www.example.com/user/ibrahim', the path part of the URI is '/user/ibrahim'. It is possible to include variables in the path. To include a variable in the path, its name must be enclosed between {}. The value of the variable will be stored in either the array $_GET or $_POST after the requested URI is resolved. If we use the same example above to get any user profile, We would add the following as a path: 'user/{username}'. In this case, username will be available in $_GET['username']. Note that its possible to get the value of the variable using the method Router::getVarValue()
- route-to: The path to the file that the route will point to. It can be any file in the scope of the variable ROOT_DIR.
- as-api: If this parameter is set to true, the route will be treated as if it was an API route. This means that the constant 'API_ROUTE' will be initiated when a request is made to the route. Note that if the PHP file that the route is pointing to represents an API, no need to add this option. Default is false.
- case-sensitive: Make the URL case sensitive or not. If this one is set to false, then if a request is made to the URL 'https://example.com/one/two', It will be the same as requesting the URL 'https://example.com/OnE/tWO'. Default is true.
- languages: An indexed array that contains the languages at which the resource can have. Each language is represented as two characters such as 'AR'.
- vars-values: An optional associative array which contains sub indexed arrays that contains possible values for URI vars. This one is used when building the sitemap.
- middleware: This can be a name of a middleware to assign to the route. This also can be a middleware group. In addition to that, this can be an array that holds middleware names or middleware groups names.
- in-sitemap: If set to true, the given route will be added to the basic site map which can be generated by the router class.
- methods: An optional array that can have a set of allowed request methods for fetching the resource. This can be also a single string such as 'GET' or 'POST'.
- action: If the class that the route is pointing to represents a controller, this index can have the value of the action that will be performed (the name of the class method).
- routes This option is used to have sub-routes in the same path. This option is used to group multiple routes which share initial part of a path.
Parameters:
- array $options An associative array that contains route options. Available options are:
- path: The path part of the URI. For example, if the requested URI is 'http://www.example.com/user/ibrahim', the path part of the URI is '/user/ibrahim'. It is possible to include variables in the path. To include a variable in the path, its name must be enclosed between {}. The value of the variable will be stored in either the array $_GET or $_POST after the requested URI is resolved. If we use the same example above to get any user profile, We would add the following as a path: 'user/{username}'. In this case, username will be available in $_GET['username']. Note that its possible to get the value of the variable using the method Router::getVarValue(). Note that for any route that points to a web services set, a variable which has the name 'service-name' must be added.
- route-to: The path to the API file. The root folder for all APIs is '/apis'. If the API name is 'get-user-profile.php', then the value of this parameter must be '/get-user-profile.php'. If the API is in a sub-directory inside the APIs directory, then the name of the directory must be included.
- case-sensitive: Make the URL case sensitive or not. If this one is set to false, then if a request is made to the URL 'https://example.com/one/two', It will be the same as requesting the URL 'https://example.com/OnE/tWO'. Default is true.
- vars-values: An optional associative array which contains sub indexed arrays that contains possible values for URI vars. This one is used when building the sitemap.
- middleware: This can be a name of a middleware to assign to the route. This also can be a middleware group. In addition to that, this can be an array that holds middleware names or middleware groups names.
- methods: An optional array that can have a set of allowed request methods for fetching the resource. This can be also a single string such as 'GET' or 'POST'.
- routes This option is used to have sub-routes in the same path. This option is used to group multiple routes which share initial part of a path.
Parameters:
- array $options An associative array that contains route options. Available options are:
- path: The path part of the URI. For example, if the requested URI is 'http://www.example.com/user/ibrahim', the path part of the URI is '/user/ibrahim'. It is possible to include variables in the path. To include a variable in the path, its name must be enclosed between {}. The value of the variable will be stored in either the array $_GET or $_POST after the requested URI is resolved. If we use the same example above to get any user profile, We would add the following as a path: 'user/{username}'. In this case, username will be available in $_GET['username']. Note that its possible to get the value of the variable using the method Router::getVarValue()
- route-to: A closure (A PHP function).
- closure-params: An array that contains values which can be passed to the closure.
- as-api: If this parameter is set to true, the route will be treated as if it was an API route. This means that the constant 'API_ROUTE' will be initiated when a request is made to the route. Default is false.
- case-sensitive: Make the URL case sensitive or not. If this one is set to false, then if a request is made to the URL 'https://example.com/one/two', It will be the same as requesting the URL 'https://example.com/OnE/tWO'. Default is true.
- languages: An indexed array that contains the languages at which the resource can have. Each language is represented as two characters such as 'AR'.
- vars-values: An optional associative array which contains sub indexed arrays that contains possible values for URI vars. This one is used when building the sitemap.
- middleware: This can be a name of a middleware to assign to the route. This also can be a middleware group. In addition to that, this can be an array that holds middleware names or middleware groups names.
- in-sitemap: If set to true, the given route will be added to the basic site map which can be generated by the router class.
- methods: An optional array that can have a set of allowed request methods for fetching the resource. This can be also a single string such as 'GET' or 'POST'.
- routes This option is used to have sub-routes in the same path. This option is used to group multiple routes which share initial part of a path.
Returns the value of the base URI which is appended to the path. This method is similar to calling the method Router::base().
Parameters:
- string $path The path part of the URI.
Parameters:
- string $url A string that represents a URL (such as 'https://example.com/my-resource').
Parameters:
- string $varName The name of the variable. Note that it must not include braces.
Parameters:
- string $path The path which will be checked (such as '/path1/path2')
Parameters:
- array $options An associative array that contains route options. Available options are:
- path: The path part of the URI. For example, if the requested URI is 'http://www.example.com/user/ibrahim', the path part of the URI is '/user/ibrahim'. It is possible to include variables in the path. To include a variable in the path, its name must be enclosed between {}. The value of the variable will be stored in either the array $_GET or $_POST after the requested URI is resolved. If we use the same example above to get any user profile, We would add the following as a path: 'user/{username}'. In this case, username will be available in $_GET['username'].
- route-to: The path to the view file. The root folder for all views is '/pages'. If the view name is 'view-user.php', then the value of this parameter must be '/view-user.php'. If the view is in a sub-directory inside the views directory, then the name of the directory must be included.
- case-sensitive: Make the URL case sensitive or not. If this one is set to false, then if a request is made to the URL 'https://example.com/one/two', It will be the same as requesting the URL 'https://example.com/OnE/tWO'. Default is true.
- languages: An indexed array that contains the languages at which the resource can have. Each language is represented as two characters such as 'AR'.
- vars-values: An optional associative array which contains sub indexed arrays that contains possible values for URI vars. This one is used when building the sitemap.
- middleware: This can be a name of a middleware to assign to the route. This also can be a middleware group. In addition to that, this can be an array that holds middleware names or middleware groups names.
- in-sitemap: If set to true, the given route will be added to the basic site map which can be generated by the router class.
- methods: An optional array that can have a set of allowed request methods for fetching the resource. This can be also a single string such as 'GET' or 'POST'.
- routes This option is used to have sub-routes in the same path. This option is used to group multiple routes which share initial part of a path.
Parameters:
Parameters:
- string $path The path part of route URI.
Parameters:
- string $uri The URI.
Parameters:
- callable $func The function which will be called if the rout is not found.
Parameters:
- RouterUri $routerUri An object of type 'RouterUri'.