Exemplo n.º 1
0
Arquivo: ste.php Projeto: rezon/sugi
<?php

/**
 * STE demo
 *
 * @package Sugi
 * @version 12.12.11
 */
include "common.php";
use Sugi\Ste;
$tpl = new Ste();
$tpl->load('ste/index.html');
$tpl->set('title', 'STE');
$tpl->set(array('description' => 'Simple Template Engine', 'keywords' => 'php, template, engine, sugi'));
$tpl->set('home', array('link' => array('href' => 'index.php', 'title' => 'back')));
$tpl->loop('mainmenu', array(array('item' => 'one'), array('item' => 'two', 'current' => ' class="current"'), array('item' => 'three')));
$tpl->loop('block', array(array('li' => '1', 'nested' => array(array('li' => '1.1'), array('li' => '1.2', 'nested2' => array(array('li' => '1.2.1'), array('li' => '1.2.2'))), array('li' => '1.3'))), array('li' => '2', 'nested' => array(array('li' => '2.1'), array('li' => '2.2'))), array('li' => '3'), array('li' => '4', 'nested' => false)));
$tpl->loop('offers', array(array('id' => 1, 'img' => false), array('id' => 2, 'img' => true), array('id' => 3, 'img' => 'alabala'), array('id' => 4)));
$tpl->register_function('test', function ($id, $html, $else = '') {
    if ($id >= 3) {
        return $html;
    }
    return $else;
});
$tpl->hide('hidden');
$tpl->set('inc', 'one.html');
// dynamic file inclusion
$tpl->set('bravo', 'Hurray!');
var_dump($tpl->is_set('bravo'));
var_dump($tpl->is_set('brava'));
echo $tpl->parse();
Exemplo n.º 2
0
Arquivo: form2.php Projeto: rezon/sugi
$form->addCheckboxList("test_checkboxList", "hair", array(1 => "Braun", 2 => "Red", 3 => "Blue"))->value(array(3))->rule("required", "Please choose a color");
$form->addText("test_age", "Age")->rule('min', 'minimum 5', 5)->rule('max', 'maximum 2000', 2000);
$form->addText("test_age2", "Age range")->rule('range', 'between 5 and 20', 5, 20);
$form->addTextarea("test_area", "Description")->rule('min_length', 'minimum 5 symbols', 5)->rule('max_length', 'maximum 2000 symbols', 2000);
$form->addTextarea("test_area2", "Descr. range")->rule('length', 'between 5 and 20', 5, 20);
$form->addText("fname", "First Name:")->rule('regexp', 'Името трябва да съдържа поне една голяма буква', '/[A-Z]/');
$form->addText("email", "Email:")->rule('email', 'should be valid email')->rule('callback', 'should be \'email@domain.com\'', 'callmeback');
function callmeback($val)
{
    return $val == '*****@*****.**';
}
$form->addText("url", "URL:")->rule('url', 'should be a valid url');
$form->addUpload("file", "test")->rule("required");
$form->addSubmit("submit", "Send");
$form->addSubmit("submit2", "Send2");
$tpl = new Ste();
$tpl->load('ste/form.html');
$tpl->set('form', $form->toArray());
$tpl->set('data', var_export($form->data(), true));
$tpl->set('form_code', htmlspecialchars($form));
if ($form->submitted()) {
    $data = $form->data();
    if ($data['test_area'] == '11') {
        $form->addError('test_area', 'Could not be 11');
    }
    if ($form->valid()) {
        $tpl->hide('form');
    }
}
header('Content-Type: text/html; charset=utf-8');
echo $tpl->parse();