Helix Installation   Getting Started   Reference Documentation   Global Functions   Quick Start
Getting StartedHelpful ResourcesAsk questions on the Help ForumRead the User GuideBrowse the Reference DocumentationSubscribe to the Helix Mailing ListLearning HelixAdvanced Topics

Codebehind Files

Helix uses codebehind files to provide functions that are ready to be called on the server once a page has loaded in the browser.  A codebehind file is simply a collection of functions that are specific to a single page in a Helix application.  Codebehind files are optional and will be loaded by Helix if they exist in the page folder.

Creating Codebehind Files

If you need to use codebehind functions for a page in your application, add a file in the page folder with the same name as the page, but with a ".cb.php" extension.  For example, you can add a codebehind file for a page named test-page by creating a file named test-page.cb.php in the test-page folder.  Once the codebehind file exists in the page folder, it will be automatically loaded by Helix when that page is requested.

Using Codebehind Files

Codebehind functions for a page are loaded every time the page is requested, every time an AJAX call is made from the browser where the page is loaded, and every time a function argument is called using the "f" parameter in a request.  The codebehind file should only contain a list of functions that are specific to the page.

See the code below for an example of how to define a function in a codebehind file and use it in several different ways:

// This is a function in the test-page.cb.php file
function test_function()
"This is a function in the codebehind file for test-page";

The following code shows how to call a codebehind function from within the markup file.

// This is the code in the markup file, test-page.php
    // When this markup file is loaded, all of the functions
    // in the codebehind file, test-page.cb.php, are also loaded
echo "About to call a function in the codebehind file:";
// This function was defined in the codebehind file
echo test_function();

The following code shows how to call a codebehind function on the server when a button is clicked in the browser.

// Codebehind functions can also be called via AJAX in
    // event handlers in the browser
    // For example, you can set the "onclick" event for an
    // HTML button element to call a codebehind function on
    // the server, and load the response in another element
    // on the page
$button = new button("Click Me");
$button->onclick ajax("test_function","response_element");
"Response from test_function() will appear here";
Get Helix PHP Framework at SourceForge.net. Fast, secure and Free Open Source software downloads