本文整理汇总了PHP中r::ajax方法的典型用法代码示例。如果您正苦于以下问题:PHP r::ajax方法的具体用法?PHP r::ajax怎么用?PHP r::ajax使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类r
的用法示例。
在下文中一共展示了r::ajax方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: layout
public function layout($type, $data = array())
{
$version = panel()->version();
$base = panel()->urls()->index();
$cssbase = panel()->urls()->css();
$jsbase = panel()->urls()->js();
$defaults = array('title' => panel()->site()->title() . ' | Panel', 'direction' => panel()->direction(), 'meta' => $this->snippet('meta'), 'css' => css($cssbase . '/panel.css?v=' . $version), 'js' => js($jsbase . '/dist/panel.min.js?v=' . $version), 'content' => '', 'bodyclass' => '');
switch ($type) {
case 'app':
$defaults['topbar'] = '';
$defaults['csrf'] = panel()->csrf();
$defaults['formcss'] = css($cssbase . '/form.min.css?v=' . $version);
$defaults['formjs'] = js($jsbase . '/dist/form.min.js?v=' . $version);
$defaults['appjs'] = js($jsbase . '/dist/app.min.js?v=' . $version);
// plugin stuff
$defaults['pluginscss'] = css($base . '/plugins/css?v=' . $version);
$defaults['pluginsjs'] = js($base . '/plugins/js?v=' . $version);
break;
case 'base':
break;
}
$data = array_merge($defaults, $data);
if (r::ajax() and $type == 'app') {
$panel = panel();
$user = $panel->site()->user();
$response = array('user' => $user ? $user->username() : false, 'direction' => $panel->direction(), 'title' => $data['title'], 'content' => $data['topbar'] . $data['content']);
return response::json($response);
} else {
return new Layout($type, $data);
}
}
示例2: error
public static function error($message, $type, $file, $line)
{
// remove everything that has been rendered so far
if (ob_get_level()) {
ob_end_clean();
}
if (class_exists('kirby') and !is_null(kirby::$instance)) {
$kirby = kirby::$instance;
} else {
$kirby = null;
}
if (r::ajax()) {
if (terror::debug()) {
echo response::error($message, 400, array('type' => $type, 'file' => $file, 'line' => $line));
} else {
echo response::error('Unexpected error', 400);
}
} else {
header::status(400);
static::view($message, $type, $file, $line, $kirby);
}
die;
}
示例3: array
/* Custom Panel Stylesheet
---------------------------------------
Define a custom stylesheet to load in to the panel. See:
getkirby.com/docs/cheatsheet/options/panel.stylesheet
*/
c::set('panel.stylesheet', 'assets/css/panel.css');
/* Kirby Configuration
---------------------------------------
By default you don't have to configure anything to
make Kirby work. For more fine-grained configuration
please check out getkirby.com/docs/advanced/options
and getkirby.com/blog/multi-environment-setup
*/
// Routes
//
c::set('routes', array(array('pattern' => '(:any)', 'method' => 'ALL', 'action' => function ($path) {
if (!r::ajax()) {
header::notfound();
return site()->visit($path);
}
$page = page($path);
$has_api_method = method_exists($page, 'api');
return response::json(array('has_api_method' => $has_api_method));
}), array('pattern' => 'get/users.json', 'method' => 'ALL', 'action' => function () {
// if(!r::ajax()) {
// return header::forbidden();
// }
// $users = site()->users()->toArray();
// $r = array_combine($users,site()->users()->toArray()); // format for kirby select field
return response::json(array("first" => 'Rafe', "middle" => 'Jackson', "last" => 'Goldberg'));
})));
示例4: run
/**
* Iterate through every route to find a matching route.
*
* @param string $path Optional path to match against
* @return Route
*/
public function run($path = null)
{
$method = r::method();
$ajax = r::ajax();
$https = r::ssl();
$routes = a::get($this->routes, $method, array());
// detect path if not set manually
if ($path === null) {
$path = implode('/', (array) url::fragments(detect::path()));
}
// empty urls should never happen
if (empty($path)) {
$path = '/';
}
foreach ($routes as $route) {
if ($route->https and !$https) {
continue;
}
if ($route->ajax and !$ajax) {
continue;
}
// handle exact matches
if ($route->pattern == $path) {
$this->route = $route;
break;
}
// We only need to check routes with regular expression since all others
// would have been able to be matched by the search for literal matches
// we just did before we started searching.
if (strpos($route->pattern, '(') === false) {
continue;
}
$preg = '#^' . $this->wildcards($route->pattern) . '$#u';
// If we get a match we'll return the route and slice off the first
// parameter match, as preg_match sets the first array item to the
// full-text match of the pattern.
if (preg_match($preg, $path, $parameters)) {
$this->route = $route;
$this->route->arguments = array_slice($parameters, 1);
break;
}
}
if ($this->route and $this->filterer($this->route->filter) !== false) {
return $this->route;
} else {
return null;
}
}
示例5: redirect
public function redirect($obj = '/', $action = false, $force = false)
{
if ($force === false and $redirect = get('_redirect')) {
$url = purl($redirect);
} else {
$url = purl($obj, $action);
}
if (r::ajax()) {
$user = $this->site()->user();
die(response::json(array('direction' => $this->direction(), 'user' => $user ? $user->username() : false, 'url' => $url)));
} else {
go($url);
}
}
示例6: function
<?php
return function ($site, $pages, $page) {
//set variables
$url = null;
$data = null;
$status = null;
//if page is accessed thorugh ajax
if (r::ajax()) {
//store sanitized $_POST variables
$currentTestData = r::postData(array('test', 'user', 'data'));
//get logged user (if any)
if ($user = Auth::loggedUser()) {
//get user's session page
$userSession = site()->find(implode(DS, array(c::get('sessions.folder'), $user->session())));
//istantiate testSession object
$tSession = new testSession($userSession, $user->username());
//get user's current session status
$userSessionStatus = $user->status();
//if ajaxed $currentTestData equals user's current session status
if (str::lower($currentTestData['test']) == str::lower($userSessionStatus)) {
//if it was possitble to update user's results file (by appending $currentTestData)
if (f::append($tSession->getUserResultsFile(), PHP_EOL . a::json($currentTestData))) {
//set updated user's session status to next avalibale test
$updatedStatus = $tSession->getNextTest($currentTestData['test']);
//if there aren't tests available, set user's session statuts to completed session
if (!$updatedStatus) {
$updatedStatus = c::get('session.status.completed');
}
//update user's session status to next avalibale test
$user->update(array('status' => $updatedStatus));
示例7: testAjax
public function testAjax()
{
$this->assertFalse(r::ajax());
}
示例8: redirect
public function redirect($obj = '/', $action = false, $force = false)
{
if ($force === false and $redirect = get('_redirect')) {
$url = purl($redirect);
} else {
$url = purl($obj, $action);
}
if (r::ajax()) {
// set the username of the current user
if ($user = site()->user()) {
header('Panel-User: ' . $user->username());
}
die(response::json(array('url' => $url)));
} else {
go($url);
}
}