Documentation

Markup

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']], ]

Lists

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

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', ]

Rendering Components

Layout

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

[ # Form data will be submitted to "/action/path" # callback() function will be fired on response 'form:/action/path:callback()' => [ # ... ] ];

Select

[ # <select name="user_id"> 'select:user_id:2' => [ 1 => 'Joe', # <option id="1">Don</option> 2 => 'Don' # <option id="2" selected>Don</option> ] ];

Input

[ # <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

[ # <textarea name="text" placeholder="Text...">t...</textarea> 'textarea:text:Text...' => 't...' ];

Hidden

[ # <input name="user_id" value="10" type="hidden"/> 'hidden:user_id' => 10 ];

File

[ # <input name="image" type="file"/> 'file:image' => '' ];

Checkbox

[ # <input type="checkbox" name="enable"/> 'check:enable' => '', # <input type="checkbox" name="premium" checked="true"/> 'check:premium' => 1 ];

Radio

[ # <input type="radio" name="type"/> 'radio:type' => 'user', # <input type="radio" name="type" checked="true"/> 'radio:type:1' => 'admin' ];

Button

[ # 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', ];

Submit

[ # <button type="submit">Go</button> 'submit' => 'Go', ];

Progress

[ # <progress value="75" max="100"></progress> 'progress' => 75, ];

Images, videos and frames

[ # <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' ];

Links

[ # <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', ]

Utilities

e($text)

Escapes $text using htmlspecialchars():

echo e("<b>t</b>test");
&lt;b&gt;t&lt;/b&gt;test

redirect($url)

Redirects to the specified $url with support of redirect when processing AJAX request:

redirect("/another/page");

nums($space)

Returns counter value for a given $space (starts from 1):

echo nums('my'); echo nums('my'); echo nums('other');
1
2
1

endpoint()

Returns current URL endpoint:

echo endpoint();
/current/path
HomeHow to build web appDocumentationGithub@Denys Golotiuk in 2024