UserCandy Documentation - System Routing
System Routing UserCandy Framework System Routing is designed to pull data from the URL to load pages for display in web browsers. How does System Routing work? When a user types in a URL, the router checks to see if there is a route set for the requested URL in the Pages database. If there is a match, the system will then check to see if the page's file exists. The router will then automatically included the files needed for that page. How does the Admin add, remove, or edit routes? The process is simple thanks to the UserCandy Framework Pages Permissions auto page detection feature. Once a new page is created within the /custom/pages/ folder, the site Admin just needs to open the Page Permissions page within the AdminPanel. The Framework will automatically detect the new page and add it to the pages database with default settings. Once this is done, if you go to the home page there will be a new link in the nav bar for that page. The page should be working. The Admin can edit the new page's settings by clicking the edit button for that page within the Pages Permissions page in the AdminPanel. The following settings can be edited within each Page Permission. User Group Permissions Check which User Groups are allowed to view the page. SiteMap.xml Check if page is to be listed within the SiteMap.xml output for SEO goods. Folder Location of the page file. Pages within the /custom/pages/ folder are set as "custompages". File Name of the page file without the .php extension. For example if you create the file /custom/pages/Demo.php this setting should be "Demo". The system router will automatically include the Demo.php file when requested. This setting is Case Sensitive. URL The URL is what the system router will match with the URL requested by the browser to load the page. For example if you want /custom/pages/Demo.php to be loaded with a URL such as http://localhost/Demo/. This setting is Case Sensitive. Arguments Arguments tell the system router what type of arguments are allowed and how many can be used for a given page. For example if you want to have the Demo page load further settings based on the URL. http://localhost/Demo/Settings/. "Settings" is considered an argument for the "Demo" page. This would be similar to http://localhost/Demo.php?argument=Settings. See below for a list of allowed arguments and samples of how to use them. Header/Footer Enabled This setting allows Admin to Enable or Disable the Header and Footer files for the selected page. When disabled, the page will only display the data within the /custom/pages/Demo.php file. Page Template Page Template lets the router know which Template folder to load template files from within the page. Route Enabled The page can be Enabled or Disabled. When Disabled the router will treat the page as if it does not exist and display an error page when requested.
What are the different types of Arguments? UserCandy Framework's router looks for three different types of Arguments. - (:any) - Allows Characters and Integers - (:num) - Allows Only Integers - (:all) - Allows Symbols, Characters, and Integers To use multiple Arguments within a page make sure to separate them with a forward slash. For example (:any)/(:num)/(:all) How do Arguments work? With UserCandy Framework routing the arguments allow the system to do more than just show a page. They allow pages to be expanded to have the ability to use more options via URL. For example when a vistitor wants to view another user's profile, they go to http://localhost/Profile/Username, and the Framework loads the selected user's profile based on the URL. The argument for the Profile page is set as follows:
Code

(:any)
To get the argument from the URL the Profile.php page is similar to the following:
Code

/** Get data from URL **/
(empty($viewVars[0])) ? $username = "" : $username = $viewVars[0];

/** Echo the Username from the URL request **/
echo "You requested the following Username: ".$username;
The above will display as follows:
Code

You requested the following Username: Username
To use multiple Arguments we can use something similar to the following: http://localhost/Demo/Hello/There/World/2134123/
Code

(:any)/(:any)/(:any)/(:num)
To get the arguments from the URL the Demo.php page is similar to the following:
Code

/** Get data from URL **/
(empty($viewVars[0])) ? $argument1 = "" : $argument1 = $viewVars[0];
(empty($viewVars[1])) ? $argument2 = "" : $argument2 = $viewVars[1];
(empty($viewVars[2])) ? $argument3 = "" : $argument3 = $viewVars[2];
(empty($viewVars[3])) ? $argument4 = "" : $argument4 = $viewVars[3];

/** Echo the Username from the URL request **/
echo "First Argument: ".$argument1."<br>";
echo "Second Argument: ".$argument2."<br>";
echo "Third Argument: ".$argument3."<br>";
echo "Forth Argument: ".$argument4."<br>";
The above will display as follows:
Code

First Argument: Hello
Second Argument: There
Third Argument: World
Forth Argument: 2134123
If you need help getting any of the above to work on your project, don't hesitate to ask on the UserCandy Forum.