To render an HTML element, array key is used as a tag name and array value is used as inner content. If key value starts from ":" it is treated as attribute:
[
# <p>123</p>
'p' => '123',
# <p class="test">123</p>
'p' => [':class' => 'test', '123'],
# <p class="test"><b>Bold</b>Normal</p>
'p' => [':class' => 'test', ['b' => 'Bold', 'Normal']],
]
For lists (e.g. ul/ol elements) items should be enclosed into additional array:
[
# <ul>
# <li>first</li>
# <li>second</li>
# </ul>
'ul' => [
['li' => 'first'],
['li' => 'second']
]
]
Classes and IDs can be set using .class and #id notation
[
# <p class="test">123</p>
'p.test' => '123',
# <p class="one two">123</p>
'p.one.two' => '123',
# <p id="body">123</p>
'p#body' => '123',
# <p id="body" class="cls">123</p>
'p#body.cls' => '123',
]
PHPy uses global app/layout.php file that contains outter markup for all internal components(pages):
<?php return [
'html' => [
# JS and CSS version (used for client caching)
':v' => 1,
# Web page title
':title' => 'Page Title',
# additional tags to include in HTML <head>
':head' => '<link href="https://fonts.googleapis.com">',
# load and render internal component based on URL
'div#content' => phpy(),
# other sample common layout elements
'#footer' => [ 'created in ' . date('Y') ]
]
];
[
# Form data will be submitted to "/action/path"
# callback() function will be fired on response
'form:/action/path:callback()' => [
# ...
]
];
[
# <select name="user_id">
'select:user_id:2' => [
1 => 'Joe', # <option id="1">Don</option>
2 => 'Don' # <option id="2" selected>Don</option>
]
];
[
# <input name="email" value="[email protected]" placeholder="Email..."/>
'input:email:Email...' => '[email protected]',
# <input name="email" type="email"/>
'input:email' => [':type' => 'email'],
# <input name="age" type="number"/>
'input' => [':type' => 'number', ':name' => 'age']
];
[
# <textarea name="text" placeholder="Text...">t...</textarea>
'textarea:text:Text...' => 't...'
];
[
# <input name="user_id" value="10" type="hidden"/>
'hidden:user_id' => 10
];
[
# <input name="image" type="file"/>
'file:image' => ''
];
[
# <input type="checkbox" name="enable"/>
'check:enable' => '',
# <input type="checkbox" name="premium" checked="true"/>
'check:premium' => 1
];
[
# <input type="radio" name="type"/>
'radio:type' => 'user',
# <input type="radio" name="type" checked="true"/>
'radio:type:1' => 'admin'
];
[
# This button will call '/path/to/action'
# <button type="button">Call server action</button>
'button:/path/to/action' => 'Call server action',
# This button will call '/path/to/action'
# and then call cb() function with response
'button:/path/to/action:cb()' => 'Call server and callback',
# This button will call test() JS function
# <button type="button">Test</button>
'button:test()' => 'Test',
# This button will confirm action with "Are you sure?"
# Then '/remove' action will be called
# and on response -> cb() JS callback
'button:/remove:cb():Are you sure?' => 'Test',
];
[
# <button type="submit">Go</button>
'submit' => 'Go',
];
[
# <progress value="75" max="100"></progress>
'progress' => 75,
];
[
# <img src="/path/to/image.jpg">
'img' => '/path/to/image.jpg',
# <video><source src="/path/to/video.mp4"></source></video>
'video' => '/path/to/video.mp4',
# <iframe src="/page.html"></iframe>
'iframe' => '/page.html'
];
[
# <a href="/page">Go</a>
'a:/page' => 'Go',
# If "(" is found, then link is treated as JS callback
# <a href="javascript:test()">Test</a>
'a:test()' => 'Test',
]
Escapes $text using htmlspecialchars():
echo e("<b>t</b>test");
<b>t</b>test
Redirects to the specified $url with support of redirect when processing AJAX request:
redirect("/another/page");
Returns counter value for a given $space (starts from 1):
echo nums('my');
echo nums('my');
echo nums('other');
1 2 1
Returns current URL endpoint:
echo endpoint();
/current/path