コード例 #1
0
ファイル: index.php プロジェクト: niceperson/dspms
<?php

//---------------------------------------------------------------------------------------
//                                    load library
//---------------------------------------------------------------------------------------
//load routing library
require 'Horus.php';
// instantiate app object
$app = new Horus();
// constant for parcel status
class ParcelStatus
{
    const UNKNOWN = 0;
    const RECEIVED = 1;
    const CLAIMED = 2;
}
//---------------------------------------------------------------------------------------
//                                   common function
//---------------------------------------------------------------------------------------
// function to create db connection
$app->dbc = function () {
    $dbuser = '******';
    $dbpass = '';
    try {
        $dbh = new PDO("mysql:host=localhost;dbname=dspms", $dbuser, $dbpass);
        return $dbh;
    } catch (PDOException $e) {
        echo $e->getMessage();
    }
};
// function to invoke sms gateway
コード例 #2
0
ファイル: index.php プロジェクト: r0lodex/dspms
<?php

//load routing library
require 'Horus.php';
// instantiate app object
$app = new Horus();
// function to create db connection
$app->dbc = function () {
    $dbuser = '******';
    $dbpass = '******';
    try {
        $dbh = new PDO("mysql:host=localhost;dbname=parcelman", $dbuser, $dbpass);
        return $dbh;
    } catch (PDOException $e) {
        echo $e->getMessage();
    }
};
//function to validate access
$app->auth = function ($token, $uid) {
    // query db for token validation
    $sql = 'SELECT id FROM user WHERE access_token=:token AND id=:id LIMIT 1';
    // bind parameter
    $prm = ['id' => $uid, ':token' => $token];
    $dbh = $this->dbc();
    $qry = $dbh->prepare($sql);
    $qry->execute($prm);
    $res = $qry->fetch(PDO::FETCH_ASSOC);
    if (empty($res)) {
        return false;
    } else {
        return true;
コード例 #3
0
ファイル: index.php プロジェクト: r0lodex/bookstore
<?php

require 'env.php';
require 'orm.php';
require 'factory.php';
require 'Horus.php';
require_once 'Twig/Autoloader.php';
Twig_Autoloader::register();
$app = new Horus();
$app->config->base = '/';
function render($path, $data = null)
{
    $loader = new Twig_Loader_Filesystem('../templates');
    $twig = new Twig_Environment($loader, array('debug' => true));
    // Figure out mcm mana nak set global to the template...
    $ENV["BOOKSTORE_TITLE"] = 'Kedai Buku SIH';
    $twig->addExtension(new Twig_Extension_Debug());
    $twig->addGlobal('env', $ENV);
    $template = $twig->loadTemplate($path . '.twig');
    echo $template->render($data);
}
// STATIC PAGES
// =======================================
$app->on('GET /', function () {
    $this->end(render('index', []));
})->on('GET /contact', function () {
    $this->end(render('contact', []));
})->on('GET /how-to', function () {
    $this->end(render('how-to', []));
})->on('GET /booklist', function () {
    $books = ['books' => run(Factory::GETBOOKLIST, [])];
コード例 #4
0
ファイル: server.php プロジェクト: r0lodex/HermoChallenge
<?php

/*
* Author  : Irfan Radzi
* Project : Hermo Challenge 2016
* January 2016
*/
require __DIR__ . '/vendor/autoload.php';
require __DIR__ . '/vendor/alash3al/horus/Horus.php';
// App not optimized for autoload...
Twig_Autoloader::register();
$app = new Horus();
$app->config->base = '/';
function render($path, $data = null)
{
    $loader = new Twig_Loader_Filesystem('../app');
    $twig = new Twig_Environment($loader, array('debug' => true));
    $twig->addExtension(new Twig_Extension_Debug());
    $template = $twig->loadTemplate($path . '.html');
    echo $template->render($data);
}
session_start();
include 'cart.php';
include 'checkout.php';
$app->on('/', function () {
    $this->end(render('index', []));
});
// CARTS API
// ================
$app->on('GET /api/cart', function () {
    $cart = isset($_SESSION['cart']) ? $_SESSION['cart'] : [];