Mecha CMS

Deep learning on using the API.

Class Page

Author: Taufik Nurrohman · 42 Views

Tweet

Working with pages.

Table of Content

Open 

Page::open($path, $lot = [], $NS = 'page');

Initialize by opening a page file:

Page::open('path\to\file.page');

Data 

->data($input, $fn = null);

Set page header:

Page::open('path\to\file.page')->data([
    'title' => 'Page Title',
    'description' => 'Page description.',
    'author' => 'Taufik Nurrohman',
    'type' => 'HTML'
]);
Page::open('path\to\file.page')->data('title', function($data) {
    return $data['author']; // ← set `author` value as the `title`
});

Set page content:

Page::open('path\to\file.page')->data('<p>Page content.</p>');

Remove title data:

Page::open('path\to\file.page')->data(['title' => false]);

Set title data as false:

Page::open('path\to\file.page')->data(['title' => 'false']);

Remove page content:

Page::open('path\to\file.page')->data(false);

Get 

->get($key = null, $fail = null, $NS = 'page');

Get title property from a page if available, otherwise, return Untitled:

$test = Page::open('path\to\file.page')->get('title', 'Untitled');

Get title and url properties from a page:

$test = Page::open('path\to\file.page')->get([
    'title' => 'Untitled',
    'url' => '#'
]);

Save 

->save($consent = 0600);

Update page data:

Page::open('path\to\file.page')->data(['title' => 'New Title'])->save();

Save To 

->saveTo($path, $consent = 0600);

Create a new page:

Page::data([
    'title' => 'Page Title',
    'type' => 'HTML',
    'content' => '<p>Page content.</p>'
])->saveTo('path\to\file.page');

Unite 

Page::unite($input);

Convert array input into page file content:

$test = Page::unite([
    'title' => 'Page Title',
    'description' => 'Page description.',
    'author' => 'Taufik Nurrohman',
    'type' => 'HTML',
    'content' => '<p>Page content.</p>'
]);

Result:

---
title: Page Title
description: Page description.
author: Taufik Nurrohman
type: HTML
...

<p>Page content.</p>

Apart 

Page::apart($input, $key = null, $fail = null);

Convert page file content into array:

$input = '---
title: Page Title
description: Page description.
author: Taufik Nurrohman
type: HTML
status: 1
...

<p>Page content.</p>';

$test_1 = Page::apart($input);
$test_2 = Page::apart($input, 'type');

Result:

$test_1 = [
    'title' => 'Page Title',
    'description' => 'Page description.',
    'author' => 'Taufik Nurrohman',
    'type' => 'HTML',
    'status' => '1', // a string
    'content' => '<p>Page content.</p>'
];
$test_2 = 'HTML';

Constructor 

Page($input = null, $lot = [], $NS = 'page');
$page = new Page('path\to\file.page');

Related: Get Page

0 Comments

No comments yet.