CMS Class

Access data from the cms sytem

get

array $cms->get( string $section, mixed $conditions=NULL, int $num_results=NULL, string $order=NULL, bool $asc=true, string $prefix=null )

This is used for pulling content from the CMS example:

Example #1 Retrieve all items

This will retrieve all items from the cms section called "news" order by date (newest first).

$news_items = $cms->get('news', null, null, 'date', false);
Example #2 Retrieve specific item

This will retrieve the item where ID = 1

$news_item = $cms->get('news', 1);

Which is equivalent to:

$news_item = $cms->get('news',array('id'=> 1));
Example #3 Retrieve by page name

This will retrieve the item where page name = "latest-news"

$news_item = $cms->get('news', 'latest-news');
Example #4 Search

This will retrieve all items where "display = true"

$news_items = $cms->get('news',
    array(
        display => true
    )
);
Example #5 Retrieve by date

This will retrieve all items from last 30 days

$news_items = $cms->get('news', array(
    'date' => '-30 days',
    'func' => array('date' => '>')
));

set_section

$cms->set_section(string $section, int $id=null, array $editable_fields );

This sets the current section - this is required before displaying fields or saving data.

Example #1 form submission

This will create a form, validate and submit.

Fields are validated if their required checkbox is ticked in the configure section.

<?
//set cms section for fields and validation
$cms->set_section('enquiries');

//handle form submission
if( isset($_POST['save']) ){
    $cms->submit(true); //true to send an email notification to admin
}
?>

<h1>Contact form</h1>
<? if( $cms->saved ){ ?>
<p>Thanks, we will be in touch..</p>
<? }else{ ?>
<form method="post" class="validate">
    <input type="hidden" name="save" value="1">
    <p><?=$cms->get_field('name', 'placeholder="your name"');?></p>
    <p><?=$cms->get_field('email', 'placeholder="your email"');?></p>
    <p><?=$cms->get_field('enquiry', 'placeholder="your enquiry"');?></p>
    <button type="submit">Submit</button>
</form>
<? } ?>

<?
//load jquery and cms.js for validation
load_js('cms');
?>
see demo

get_field

$cms->get_field( string $name, string $attribs='' );

This outputs a form field like a text input box or a rich text area.
$attribs are added into the field so that you can add class names and other attributes.

save

$cms->save();

Takes post data and uses it to save to the currently set section.
If an item is selected it will be updated - otherwise a new item will be created.

delete_items

$cms->delete_items( string $section, mixed $items );

Deletes a single id or an array of ids from the provided CMS section.