本文整理汇总了PHP中app\App::instance方法的典型用法代码示例。如果您正苦于以下问题:PHP App::instance方法的具体用法?PHP App::instance怎么用?PHP App::instance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\App
的用法示例。
在下文中一共展示了App::instance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionDelete
public function actionDelete()
{
if (!isset($_POST['imageId'])) {
App::instance()->show404();
exit;
}
/** @var \models\Image $model */
$model = Image::findByID((int) $_POST['imageId']);
if (!$model || $model->uid != App::instance()->getUser()->getId()) {
App::instance()->show404();
exit;
}
if ($model->delete()) {
$response['error'] = false;
} else {
$response = json_encode(['error' => true]);
}
if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && 'XMLHttpRequest' === $_SERVER['HTTP_X_REQUESTED_WITH']) {
$response['totalCount'] = Image::countByProp('uid', App::instance()->getUser()->getId());
echo json_encode($response);
} else {
$this->redirect('/site/index/');
echo $response;
}
}
示例2: actionLogout
public function actionLogout()
{
if (!App::instance()->isGuest()) {
App::instance()->logoutUser();
}
$this->redirect('/site/index/');
}
示例3: instance
/**
* Returns the singleton instance of this class.
*
* @return DatabaseService
*/
public static function instance()
{
if (!isset(self::$instance)) {
$db = App::instance()->config['db'];
self::$instance = new \PDO('mysql:host=' . $db['host'] . ';dbname=' . $db['name'], $db['username'], $db['password'], $db['options']);
}
return self::$instance;
}
示例4: __construct
/**
* Constructor
*/
public function __construct()
{
//create new App instance if no one
$this->_connection = App::instance()->getDb();
$currencyDbName = Processor::$currencyDbInfo['tableName'];
$sql = "SELECT id ,pair FROM {$currencyDbName}";
$stmnt = $this->_connection->query($sql);
$results = $stmnt->fetchAll(PDO::FETCH_ASSOC);
foreach ($results as $result) {
$this->_currencyPairs[$result['pair']] = (int) $result['id'];
}
}
示例5: isUnique
/**
* @param BaseModel $model
* @param $propName
*/
public static function isUnique(BaseModel $model, $propName, $scenario = [])
{
if (isset($model->{$propName}) && (empty($scenario) || in_array($model->scenario, $scenario))) {
/** @var PDO $connection */
$connection = App::instance()->getDB();
$modelTable = $model::tableName();
$sql = "SELECT COUNT(id) AS cnt FROM {$modelTable} WHERE {$propName} = :value";
$stmnt = $connection->prepare($sql);
$stmnt->execute([':value' => $model->{$propName}]);
$result = $stmnt->fetch(PDO::FETCH_ASSOC);
if (false !== $result && 0 == $result['cnt']) {
return;
}
$model->addErrorMsg($propName, 'Already exists.');
}
}
示例6: __construct
/**
* Constructor
*/
public function __construct()
{
$this->_connection = App::instance()->getDb();
$tableName = static::$periodsDbInfo['tableName'];
$sql = "SELECT id, value FROM {$tableName}";
$stmnt = $this->_connection->query($sql);
$results = $stmnt->fetchAll(PDO::FETCH_ASSOC);
foreach ($results as $result) {
$this->_periods[(int) $result['id']] = (int) $result['value'];
}
$currencyDbName = static::$currencyDbInfo['tableName'];
$sql = "SELECT id ,pair FROM {$currencyDbName}";
$stmnt = $this->_connection->query($sql);
$results = $stmnt->fetchAll(PDO::FETCH_ASSOC);
foreach ($results as $result) {
$this->_currencyPairs[$result['pair']] = (int) $result['id'];
}
}
示例7: getBtceAvgData
public function getBtceAvgData($periodId, $dateStart = null, $dateEnd = null)
{
$periodId = (int) $periodId;
if (!in_array($periodId, array_keys($this->_periods))) {
throw new \Exception('Parameter error. Wrong period ID.');
}
$connection = App::instance()->getDb();
$tableName = Processor::$btceDbInfo['statTableName'];
$currencytableName = Processor::$currencyDbInfo['tableName'];
$tsQuery = '';
$tsQuery .= $dateStart ? ' AND ts >= ' . (int) $dateStart : '';
$tsQuery .= $dateEnd ? ' AND ts <= ' . (int) $dateEnd : '';
$sql = "SELECT cp.name AS name, ts, ask, bid, high, low, avg_val, vol, vol_cur FROM {$tableName} AS st\n LEFT JOIN {$currencytableName} AS cp ON cp.id = st.pair_id\n WHERE st.period_id = {$periodId} {$tsQuery}";
$stmnt = $connection->query($sql);
if (!$stmnt) {
return [];
}
$result = $stmnt->fetchAll(PDO::FETCH_ASSOC);
return $result;
}
示例8: isset
<?php
/**
* Site index file
*/
namespace web;
use app\App;
include '../app/autoloader.php';
App::instance()->init();
$requestedPath = isset($_GET['requestedPath']) ? $_GET['requestedPath'] : '';
App::instance()->route($requestedPath);
示例9: login
/**
* @return bool
*/
public function login()
{
$dbUser = User::findByProp('email', $this->email);
if (isset($dbUser) && $this->generatePasswordHash($this->password) === $dbUser->passwordHash) {
//change user App for dbUser
App::instance()->setUser($dbUser);
return true;
}
$this->addErrorMsg('email', 'Unknown email or password. Try again.');
return false;
}
示例10: isset
<?php
/**
* @var app\View $this
*/
use app\App;
?>
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title><?php
echo isset($this->title) ? $this->title : App::instance()->appName;
?>
</title>
<link rel="stylesheet" href="/css/bootstrap.min.css">
<link rel="stylesheet" href="/css/site.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script type="text/javascript" src="/js/bootstrap.min.js"></script>
</head>
<body>
<div id="content-container">
<?php
echo $this->content;
?>
<div class="clearfix"></div>
</div>
<div class="footer">
<span><?php
echo date('Y');
?>
示例11: getUserImgDirectory
/**
* @return string
*/
public function getUserImgDirectory()
{
$path = str_replace('/', DIRECTORY_SEPARATOR, App::instance()->getWebRootPath() . '/' . $this->getUserImgDirectoryRel());
if (!file_exists($path)) {
mkdir($path, 0777, true);
}
return $path;
}
示例12: methodNotAllowed
/**
* Render "Method Not Allowed" error response.
*
* @param $method String - Requested method
* @param $url String - Requested URI.
*/
public static function methodNotAllowed($method, $url)
{
self::setHeaders(405);
$errorMessage = ['error' => 'Method Not Allowed', 'message' => 'The requested method ' . $method . ' is not allowed for the URL ' . $url . '.'];
echo json_encode($errorMessage, App::instance()->config['json_options']);
exit;
}
示例13: foreach
<?php
/**
* @var app\View $this
* @var models\Image $image
*/
use app\App;
$this->title = "Gallery: Add new image.";
?>
<div class="container col-sm-8 col-sm-offset-2">
<div id="upload-inner-container">
<h1><?php
echo App::instance()->getUser()->name;
?>
's Gallery: add new image.</h1>
<hr>
<form action="/site/upload/" method="POST" enctype="multipart/form-data">
<div class="row">
<div class="form-group<?php
echo $image->hasErrors('imageFile') ? ' has-error' : '';
?>
">
<label class="control-label" for="image-file">File:</label>
<input type="file" class="form-control" name="Image[imageFile]" id="image-file" accept="image/*">
</div>
<?php
if ($image->hasErrors('imageFile')) {
?>
<?php
foreach ($image->getErrorMsg('imageFile') as $msg) {
?>
示例14:
<?php
$config = (require_once __DIR__ . '/app/config/config.php');
require_once __DIR__ . '/app/services/AutoLoaderService.php';
require_once __DIR__ . '/app/App.php';
use App\App;
$app = App::instance();
$app->run($config);
示例15: countByProp
public static function countByProp($propName, $propVal)
{
if (!is_string($propName)) {
throw new \Exception('PropName type should be string!');
}
if (!property_exists(get_called_class(), $propName)) {
throw new \Exception('Property "' . $propName . '" not found in ' . get_called_class() . '!');
}
if (!in_array($propName, static::$dbProperties)) {
throw new \Exception('Property "' . $propName . '" should be in "static::$dbProperties" array!');
}
$tableName = static::tableName();
$sql = "SELECT COUNT(id) FROM {$tableName}\n WHERE {$propName} = :{$propName}\n LIMIT 1";
$connection = App::instance()->getDB();
$stmnt = $connection->prepare($sql);
$stmnt->bindValue(":{$propName}", $propVal);
$stmnt->setFetchMode(PDO::FETCH_NUM);
$stmnt->execute();
$result = $stmnt->fetch();
if (isset($result[0])) {
return $result[0];
}
return null;
}