本文整理汇总了PHP中Flight::set方法的典型用法代码示例。如果您正苦于以下问题:PHP Flight::set方法的具体用法?PHP Flight::set怎么用?PHP Flight::set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Flight
的用法示例。
在下文中一共展示了Flight::set方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: session_start
<?php
session_start();
define('ROOT', dirname(__FILE__));
require "flight/Flight.php";
require 'constants/conContainer.php';
require "models/modContainer.php";
require "controllers/objContainer.php";
require "tools/tooContainer.php";
/*引入配置文件*/
$error_info = parse_ini_file("configs/error.ini");
Flight::set('errorn', $error_info);
Flight::route('/', function () {
echo 'hello world! :-)';
});
Flight::start();
示例2: init
public static function init()
{
date_default_timezone_set("Etc/GMT");
if (get_magic_quotes_gpc()) {
$_GET = self::stripslashesDeep($_GET);
$_POST = self::stripslashesDeep($_POST);
$_COOKIE = self::stripslashesDeep($_COOKIE);
}
$_REQUEST = array_merge($_GET, $_POST, $_COOKIE);
Flight::map("db", array(__CLASS__, "db"));
//Flight::map("cache", array(__CLASS__, "cache"));
Flight::map("log", array(__CLASS__, "log"));
Flight::map("curl", array(__CLASS__, "curl"));
Flight::map("halt", array(__CLASS__, "halt"));
Flight::map("getRunTime", array(__CLASS__, "getRunTime"));
Flight::map("returnJson", array(__CLASS__, "returnJson"));
Flight::map("controller", array(__CLASS__, "getController"));
Flight::map("model", array(__CLASS__, "getModel"));
Flight::map("url", array(__CLASS__, "url"));
Flight::map("connectMysqlDB", array(__CLASS__, "connectMysqlDB"));
Flight::map("closeMysqlDB", array(__CLASS__, "closeMysqlDB"));
Flight::map("connectMongoDB", array(__CLASS__, "connectMongoDB"));
Flight::map("closeMongoDB", array(__CLASS__, "closeMongoDB"));
Flight::map("connectRedis", array(__CLASS__, "connectRedis"));
Flight::set('flight.log_errors', true);
//写一个日志
//if(Flight::request()->method == "POST") {
// Flight::log("post-".date("Ymd"))->info(print_r($_POST, TRUE));
//}
self::initRoute();
}
示例3: checkAdmin
/**
* check if user is logged in as admin
*/
private function checkAdmin()
{
$admin = false;
if (isset($_SESSION['admin'])) {
F::set('admin', 1);
$admin = true;
}
F::view()->assign(array('admin' => $admin));
}
示例4: testGetAndSet
function testGetAndSet()
{
Flight::set('a', 1);
$var = Flight::get('a');
$this->assertEquals(1, $var);
Flight::clear();
$vars = Flight::get();
$this->assertEquals(0, count($vars));
Flight::set('a', 1);
Flight::set('b', 2);
$vars = Flight::get();
$this->assertEquals(2, count($vars));
$this->assertEquals(1, $vars['a']);
$this->assertEquals(2, $vars['b']);
}
示例5: sd_location_data
/**
* Get, and store for the session, location data for the current visitor
*
* @return object IP location data.
*/
function sd_location_data()
{
$key = 'sd.location';
$data = Flight::get($key);
if (empty($data)) {
if (isset($_SERVER['HTTP_CF_CONNECTING_IP'])) {
$_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_CF_CONNECTING_IP'];
}
if ('dev' == ENV) {
$_SERVER['REMOTE_ADDR'] = '';
}
$path = 'https://freegeoip.net/json/' . $_SERVER['REMOTE_ADDR'];
$data = file_get_contents($path);
Flight::set($key, $data);
}
return json_decode($data);
}
示例6: avg
<?php
if (!function_exists('avg')) {
function avg(array $data)
{
return array_sum($data) / count($data);
}
}
/**
* Registers a class and set a variable to framework method.
*
* @param string $name Method name
* @param string $class Class name
* @param array $params Class initialization parameters
* @param callback $callback Function to call after object instantiation
* @throws \Exception If trying to map over a framework method
*/
Flight::map('instance', function ($name, $class, array $params = array(), $callback = null) {
Flight::register($name, $class, $params, $callback);
Flight::set($name, Flight::$name());
});
示例7: set
public function set($key, $value)
{
return Flight::set($key, $value);
}
示例8: related
<?php
require_once 'vendor/autoload.php';
// Config views
Flight::set(array('flight.views.path' => './app', 'flight.views.extension' => '.html'));
class Api
{
public static function related($id)
{
$headers = array("Accept" => "application/json");
$url = "https://api.spotify.com/v1/artists/{$id}/related-artists";
$related_artists = Unirest\Request::get($url, $headers)->body->artists;
Flight::json($related_artists);
}
public static function toptrack($artist_id)
{
$headers = array("Accept" => "application/json");
$url = "https://api.spotify.com/v1/artists/{$artist_id}/top-tracks?country=US";
$artist_top_track = Unirest\Request::get($url, $headers)->body;
Flight::json($artist_top_track);
}
}
Flight::route('GET /', function () {
Flight::render('index');
});
Flight::route('GET /api/related/@id', array('Api', 'related'));
Flight::route('GET /api/toptrack/@artist_id', array('Api', 'toptrack'));
Flight::start();
示例9: function
<?php
Flight::set("organizer.settings.path", "config/settings.json");
Flight::map("read_settings", function () {
if (($settings = file_get_contents(Flight::get("organizer.settings.path"))) !== false) {
return json_decode($settings, true);
} else {
return false;
}
});
Flight::map("load_settings", function () {
$settings = Flight::read_settings();
Flight::set("organizer.settings", $settings);
return $settings;
});
Flight::map("setting", function ($path) {
$settings = Flight::get("organizer.settings");
foreach (explode(".", $path) as $key) {
$settings = $settings[$key];
}
return $settings;
});
Flight::map("write_settings", function ($settings) {
$settings = json_encode($settings);
return file_put_contents(Flight::get("organizer.settings.path"), $settings);
});
Flight::map("dump_settings", function () {
return Flight::write_settings(Flight::get("organizer.settings"));
});
示例10: function
<?php
require __DIR__ . '/database/bootEloquent.php';
Flight::set('flight.views.path', __DIR__ . '/views');
// routes
Flight::route('/', function () {
Flight::render('hello.php', ['pessoas' => Pessoa::all()]);
});
Flight::route('POST /pessoas', function () {
$pessoa = new Pessoa();
$pessoa->nome = Flight::request()->data['nome'];
$pessoa->save();
Flight::redirect('/');
});
Flight::start();
示例11: array
<?php
Flight::route('*', array('Base', 'index'));
Flight::route('/', function () {
Flight::redirect('/admin/index');
});
Flight::route('/backend/*', function () {
Flight::redirect('/admin/index');
});
// 运行action
Flight::route("/@app/@act", function ($app, $act) {
$class = ucwords("{$app}");
// 设置当前操作在全局变量里面
Flight::set('app', strtolower($app));
Flight::set('act', $act);
$class::$act();
});
示例12: function
<?php
Flight::path("model/");
Flight::path("controller/");
Flight::register('db', 'mysqli', [$config['db']['host'], $config['db']['username'], $config['db']['password'], $config['db']['databasename']]);
Flight::register("util", "util");
Flight::register("auth", "authController");
Flight::register("posts", "postController");
Flight::register("users", "userController");
Flight::set("flight.base_url", $config['web']['base_url']);
Flight::map('link', function ($url) {
echo Flight::get('flight.base_url') . $url;
});
示例13: define
<?php
# Site name to appear in the <title> tags and footer copyright text
define('SITE_NAME', 'Your Name');
# Database connection information
Flight::register('db', 'PDO', array('sqlite:../db.sqlite3'));
# The directory to look for views in
Flight::set('flight.views.path', '../views');
# The file extension of view files
Flight::set('flight.views.extension', '.phtml');
示例14: Config
<?php
/**
* @copyright Copyright (C) 2015 hiphper, All rights reserved.
* @license GNU/GPL V2 http://gnu.org/licenses/gpl-2.0.html
* @author hiphper at 163 dot com
* @link https://github.com/hi-phper/xieblog
*/
require 'vendor/autoload.php';
require 'libs/Config.php';
require 'libs/Post.php';
use JasonGrimes\Paginator;
$config = new Config('config.json');
Flight::set('flight.views.path', './templates/' . $config->get('template'));
Flight::route('/', function () use($config) {
$post = new Post();
$page = 1;
$posts = $post->getPosts($page, $config->get('per_page'));
$totalItems = count($post->getPostNames());
$urlPattern = $config->get('base_url') . 'page/(:num)';
$paginator = new Paginator($totalItems, $config->get('per_page'), $page, $urlPattern);
Flight::render('index', array('posts' => $posts, 'config' => $config, 'paginator' => $paginator), 'content_layout');
Flight::render('layouts/default');
});
Flight::route('/page/@page', function ($page) use($config) {
$post = new Post();
$posts = $post->getPosts($page, $config->get('per_page'));
$totalItems = count($post->getPostNames());
$urlPattern = $config->get('base_url') . 'page/(:num)';
$paginator = new Paginator($totalItems, $config->get('per_page'), $page, $urlPattern);
Flight::render('index', ['posts' => $posts, 'config' => $config, 'paginator' => $paginator], 'content_layout');
示例15: session_start
<?php
require_once "flight/Flight.php";
require_once "conf/config.php";
require_once "conf/settings.php";
session_start();
Flight::set('currentUser', isset($_SESSION['user']) ? $_SESSION['user'] : null);
require_once "conf/routes.php";
Flight::start();