-
Notifications
You must be signed in to change notification settings - Fork 3
Access data from the cms sytem
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' => '>') ));
$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_section('enquiries');
//handle form submission if( isset($_POST['save']) ){ $cms->submit(true); //true to send an email notification to admin } ?>
saved ){ ?>
Thanks, we will be in touch..
get_field('name', 'placeholder="your name"');?>
get_field('email', 'placeholder="your email"');?>
get_field('enquiry', 'placeholder="your enquiry"');?>
<button type="submit">Submit</button>
EOD;
print htmlspecialchars($str); ?>`
$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.
$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.
$cms->delete_items( string $section, mixed $items );
Deletes a single id or an array of ids from the provided CMS section.