Office Hours
Day Hours (GMT)
Bank Holidays Closed
Monday 9:00 - 17:30
Tuesday 9:00 - 17:30
Wednesday 9:00 - 17:30
Thursday 9:00 - 17:30
Friday 9:00 - 17:30
Saturday Closed
Sunday Closed
Knowledgebase: Developer Articles
How do I create a new front end dynamic section or page?
Posted by Al Brookbanks on 22 November 2012 11:57 AM

This article has been written to explain how a custom section or page can be added to the front end of CubeCart. For example you may want to add a dynamic page for a feature CubeCart doesn't currently support such as a wishlist or store news.

Before going any further we would suggest getting an understanding of the Hooks system used by CubeCart in this article

CubeCart has a number of contoller files that use URL values to determine what content to show. With Search Engine Optimisation turned off you may see these in the URL with the GET variable "_a". For example if the value of "_a" is "product" CubeCart will load the product detail page. "basket" would load the carts vew/edit basket page. 

Lets say that we wanted to create a news section and intend to set the GET variable "_a" with the value of "news". In our browser the URL will look something like:

With this attribute in place CubeCart will take the following directions to find the location of source code it needs.

1. index.php loads the encoded index_*_enc_*.php file
2. the encoded file will load the controller file controllers/
3. the controller file loads up the required classes, functions and libraries required to operate the store. 
4. this controller file initilizes the CubeCart class method "loadPage" with the code $GLOBALS['cubecart']->loadPage(); from the classes/cubecart.class.php file. 
5. this method take the value of "_a" (if "_g" is not set) and performs a switch to see if there are any matches for it to work from. If there are not the default section of the switch is executed with the following code:

$method = '_'.strtolower($_GET['_a']);
// CubeCart will auto load any class in the classes folder. Please use the method below to 
// load a function from the class. e.g. widget.class.php   
if (method_exists($this, $method)) { 

// and/or you can use code from a hook in the plugins folder.  
foreach ($GLOBALS['hooks']->load('class.cubecart.construct') as $hook) include $hook;

From this block of code we have two methods of getting our code into CubeCart. Whichever you choose it totally up to you however method 2 bypasses the need for whole plugin to be created.

Method 1 - from a plugin:
Assuming that you have read and understood the hooks documentation we can see that a hook can now be used to create your page data and load any custom template files you may wish to from your plugins folder.

Method 2 - from a single class file:
Alternatively it is possible to create a custom class for your code in the classes folder with the same name as the value of the GET variable "_a". For example "classes/news.class.php". If this class exists and the method within the class has been initiated it is possible to work this way. CubeCart has a class autoloader system in that it will automatically load any class file in the classes folder with the naming convention *.class.php. 

©2017 CubeCart Limited. All rights reserved. CubeCart Limited is a company registered in England & Wales under number 5323904. VAT Registration Number GB886451190.