Creating Your First Page
In this section we will go over how to create your first custom page in your UserCandy Framework project. We are going to create Demo.php and expand from there.
Creating Demo.php
We want to open up our UserCandy Framework project folder and navigate to
/custom/pages/. We will create Demo.php within that folder. Make sure that the file's extension is *.php as the Framework only looks for *.php files.
Code
/custom/pages/Demo.php
Open the Demo.php file with your editing software of choice. Notepad works just fine. For testing purposes lets go ahead and echo Hello World in the Demo.php file. Copy and paste the following code:
Code
<?php
echo "Hello World";
?>
Now if we try to open the page in our web browser via http://localhost/Demo/ we will get an error page saying the page could not be found. If you are logged in as an Administrator you will see a button near the bottom of the page that if clicked will take you straight to the AdminPanel -> Pages Permissions page. Click that button.
You should see a success message at the top of the page that looks like this:
Code
Success! New Pages Have Been Added to Database!
URL: Demo (custompages - Demo)
Demo Added to Site Links
Now we can navigate to http://localhost/Demo/ and should see
Hello World displayed. Also you should see a
Demo link in the nav bar. If you see
Hello World then your Demo.php page is loading properly. You can add more data to the Demo.php file and refresh your browser to see the additions.
Get in the habit of setting the
Page Permissions for all pages created right after created to limit the risk of forgetting to set the permissions. Want to make sure that if a page should only be viewed by Administrators that we have that setting enabled early on. Don't want to forget and someone that is not an Administrator have access to the page when they should have been kicked out. If a user does not have permission to view a page the UserCandy Framework will automatically redirect them to the home page. All new pages are set as
Public with
SiteMap enabled by default.
Let's say we want Demo.php to only be viewed by the Administrator User Group. Open the Demo Page Permissions and make sure that only Administrator is checked. Also we suggest to disable the SiteMap by unchecking it when a page is not a Public page. Don't want Bots looking for pages they don't have access to. Once the Permissions are selected for that page just click on the Update Page button. You should see the following success message:
Code
Success! Page Permissions have been updated!
- Changed Settings for page:
- Removed Public Permission for page: Demo
- Added Administrator Permission for page: Demo
Now that the page can only be viewed by the Administrator group, we want to hide the nav bar link for Demo when a non Administrator user is viewing the site. Navigate to AdminPanel -> Site Links. You should see a list of links in the
Header Main Site Links card. Click on the green edit button for the Demo link. The
Site Link Editor - Update page will open. Click on the
Permission dropdown and select
Administrator and click the Update Link button. You should see the following success message:
Code
Success! You Have Successfully Updated Site Link
Now if you logout you will see that the
Demo links is no longer displayed in the nav bar. Now login as an Administrator and you will see that the
Demo link shows up. You can also try logging out and navigating to http://localhost/Demo/ and the site will redirect you to the Login page. If you login as a user that is not a member of the Administrator group and try to navigate to http://localhost/Demo/ you should get redirected to the home page with a simple error message at the top of the page that lets you know you do not have permission to view the page.
This should cover the basics to creating a new page and setting it up to work with your UserCandy Framework project. If you get suck or need help please use the UserCandy Forum.