Skip to content

PHP Application Guide

Guilherme Barile edited this page Feb 27, 2014 · 2 revisions

PHP Application Guide

On a PHP Application, controllers handle data and rendering templates on the server.

app/
    templates/
    _init.php
    index.php

Application Controllers

index.php

<?php

include_once '../objectiveweb/_init.php';

route('GET /?', 'handle_get');
route('POST /?', 'handle_post');

function handle_get() {
    assign('posts', get('guestbook'));
    render('index');
}

function handle_post() {
    $data = parse_post_body();

    // perform validation
    post('guestbook', $data);

    redirect('index.php');
}

Template functions

assign($var, $value)

Assigns a template variable which can be printed using {$var} on the template file.

aassign($values)

Just like assign but assigns all variables on the provided associative array of key/value pairs.

render($template)

Clone this wiki locally