</> Developers Guide to Funraisin

Custom PHP

Sometimes you need to add in server side processing into various pages so for this we support the ability to add in custom PHP code into various parts of the admin.

PHP & Codeignitor

As mentioned in the introduction Funraisin is built using the PHP framework called CodeIgnitor, version 3.1.11 at the time of writing so you are able to use pretty much all of the CodeIgnitor framework when adding in custom PHP.

Or if you prefer you can just use standard PHP keeping in mind the PHP version your site is running off which will be most likely 5.6

Pages vs Templates vs Content Blocks

When thinking of adding in custom PHP code the first thing you need to decide on is where the best place is to add it and that decision will be based on what it is you are trying to achieve.

The best thing to do is to think of it as if you were building a pure PHP page from scratch, depending on your needs you would most likely consider between in-page PHP (code added throughout the page whilst it is rendered to process output based on something such as a url parameter) or pre-rendered PHP (code added before the page is rendered where you might process data submitted from a page and possibly redirect out to another).

You also will want to think about where on the site you need the code, if you are wanting to add code to a registration flow for example then you will need to look at the template used for that step but if you are working with just a CMS page then you can add it to the page directly.

Content Blocks

If you are wanting to add code to a page that is already rendering then your choices would be either using Content Blocks or Templates and the deciding factor will be if you want it to be on a page controlled via the CMS which means it will only be available for that page or if you want it to appear on pages outside of the CMS e.g. registation flows in which case you would want to add it to the template.

Assuming we are not editing a template and we are working with the Page Builder then you will want to add a "code block" to your page. A code block can support either JS, CSS or PHP.

The important thing to know about using PHP within a codeblock is that you can't access data from outside of the block itself other than $_GET and $_POST variables. So you can't see a variable at the top of the page and get access to that variable within another block further down the page.

Also you can't use $this within a content block. See below for a solution to this.

The most common use in this scenario is displaying content based on the URL using $_GET vars or accessing something from the Database to display content e.g. a custom featured fundraisers block of content.

Page Level (pre-render)

When there is a need to process data before a page has rendered and possibly also then redirect out to another page you would want to look at adding PHP to the page itself using the built in PHP section under Advanced Options when editing a page.

This code will be executed before the page starts to render so it's ideal for processing $_POST data and inserting it into the Database and redirecting out to a thank you page, etc.

As with content blocks, the important thing to keep in mind is that any variables you set here will only be available to the code you are adding, you can't set any variables here that can be accessed in the page via content blocks.

Additionally it's important to understand that you can't access CodeIngitor using $this if you want to interact with CI components then you will need to use the below method

$CI =& get_instance();

and then you can use $CI->db->query() etc to interact with CI components.

Template Level

Finally when there is a need to add custom PHP code to pages outside of the PageBuilder such as Registration Pages and Fundraising pages then you will want to look at editing templates.

See here for our guide on that.