本文整理汇总了PHP中json类的典型用法代码示例。如果您正苦于以下问题:PHP json类的具体用法?PHP json怎么用?PHP json使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了json类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _send_reset
private function _send_reset($form)
{
$user_name = $form->reset->inputs["name"]->value;
$user = user::lookup_by_name($user_name);
if ($user && !empty($user->email)) {
$user->hash = random::hash();
$user->save();
$message = new View("reset_password.html");
$message->confirm_url = url::abs_site("password/do_reset?key={$user->hash}");
$message->user = $user;
Sendmail::factory()->to($user->email)->subject(t("Password Reset Request"))->header("Mime-Version", "1.0")->header("Content-type", "text/html; charset=UTF-8")->message($message->render())->send();
log::success("user", t("Password reset email sent for user %name", array("name" => $user->name)));
} else {
if (!$user) {
// Don't include the username here until you're sure that it's XSS safe
log::warning("user", t("Password reset email requested for user %user_name, which does not exist.", array("user_name" => $user_name)));
} else {
log::warning("user", t("Password reset failed for %user_name (has no email address on record).", array("user_name" => $user->name)));
}
}
// Always pretend that an email has been sent to avoid leaking
// information on what user names are actually real.
message::success(t("Password reset email sent"));
json::reply(array("result" => "success"));
}
示例2: reset_api_key
public function reset_api_key()
{
access::verify_csrf();
rest::reset_access_key();
message::success(t("Your REST API key has been reset."));
json::reply(array("result" => "success"));
}
示例3: make_call
public function make_call($path, $data = array(), $method = "GET")
{
$fields = $this->getFields($data);
$field_string = implode('&', $fields);
//open connection
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//what type of request?
if ($method == "GET") {
curl_setopt($ch, CURLOPT_URL, $this->api_url . $path . '?' . $field_string);
} elseif ($method == "POST" || $method == "PATCH" || $method == "DELETE") {
if ($method == "PATCH") {
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PATCH");
}
if ($method == "DELETE") {
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
}
curl_setopt($ch, CURLOPT_URL, $this->api_url . $path);
curl_setopt($ch, CURLOPT_POST, count($fields));
curl_setopt($ch, CURLOPT_POSTFIELDS, $field_string);
}
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
//send our data back
return json::decode($result);
}
示例4: confirm
public function confirm()
{
access::verify_csrf();
$messages = array("error" => array(), "warn" => array());
$desired_list = array();
foreach (module::available() as $module_name => $info) {
if ($info->locked) {
continue;
}
if ($desired = Input::instance()->post($module_name) == 1) {
$desired_list[] = $module_name;
}
if ($info->active && !$desired && module::is_active($module_name)) {
$messages = array_merge($messages, module::can_deactivate($module_name));
} else {
if (!$info->active && $desired && !module::is_active($module_name)) {
$messages = array_merge($messages, module::can_activate($module_name));
}
}
}
if (empty($messages["error"]) && empty($messages["warn"])) {
$this->_do_save();
$result["reload"] = 1;
} else {
$v = new View("admin_modules_confirm.html");
$v->messages = $messages;
$v->modules = $desired_list;
$result["dialog"] = (string) $v;
$result["allow_continue"] = empty($messages["error"]);
}
json::reply($result);
}
示例5: encodeData
function encodeData()
{
$this->data = $this->pretty_output ? json::pretty($this->data) . "\n" : json_encode($this->data);
if ($this->data === null) {
$this->throwJSONError(false, 'Failed to encode $data (' . gettype($this->data) . ') as JSON');
}
}
示例6: get_member_list
private function get_member_list()
{
// Call site settings for stored roster & member ranks to track
$siteSettings = site::setting();
// Decode JSON from stored roster data
$roster = json_decode($siteSettings[0]['fullRoster'], true);
$data = array();
// Decode JSON from stored roster ranks
$ranks = json_decode($siteSettings[0]['rosterRanks'], true);
$filterRanks = array();
// Ranks to track
foreach ($ranks as $key => $value) {
try {
// echo $key . ' == ' . $value['track'] . '<br/>';
if ($value['track']) {
$filterRanks[] = $key;
}
} catch (Exception $e) {
//
}
}
foreach ($roster['members'] as $key => $character) {
// echo var_dump($character['character']);
// echo $character['character']['name'];
if (in_array($character['rank'], $filterRanks)) {
$data[] = $character['character']['name'];
}
}
json::resp(array('success' => true, 'data' => $data));
}
示例7: request
function request($type, $url, $get = [], $post = [])
{
$developer = cookie::developer();
if ($developer) {
$get['_mode'] = 'developer';
}
$request = ['method' => $type, 'protocol_version' => '1.1', 'header' => 'Connection: Close'];
foreach ($post as $name => &$param) {
if (is_array($param) and empty($param)) {
$param = '_empty_array';
}
}
if (!empty($post)) {
$request['header'] .= "\r\nContent-type: application/x-www-form-urlencoded";
$request['content'] = http_build_query($post);
}
$ctx = stream_context_create(['http' => $request]);
$response = file_get_contents($this->endpoint . (empty($get) ? $url : $url . '?' . http_build_query($get)), false, $ctx);
$object = json::decode($response, true);
if (is_null($object)) {
if ($developer) {
var_dump($response);
die;
} else {
throw new Exception("Error Processing Request", 1);
}
}
$content = $object['content'];
return (is_object($content) or is_array($content) and array_values($content) !== $content) ? (object) $content : $content;
}
示例8: auth
public function auth()
{
if (!identity::active_user()->admin) {
access::forbidden();
}
access::verify_csrf();
$form = self::_form();
$valid = $form->validate();
$user = identity::active_user();
if ($valid) {
module::event("user_auth", $user);
if (!request::is_ajax()) {
message::success(t("Successfully re-authenticated!"));
}
url::redirect(Session::instance()->get_once("continue_url"));
} else {
$name = $user->name;
log::warning("user", t("Failed re-authentication for %name", array("name" => $name)));
module::event("user_auth_failed", $name);
if (request::is_ajax()) {
$v = new View("reauthenticate.html");
$v->form = $form;
$v->user_name = identity::active_user()->name;
json::reply(array("html" => (string) $v));
} else {
self::_show_form($form);
}
}
}
示例9: save
public function save($module_name, $var_name)
{
access::verify_csrf();
module::set_var($module_name, $var_name, Input::instance()->post("value"));
message::success(t("Saved value for %var (%module_name)", array("var" => $var_name, "module_name" => $module_name)));
json::reply(array("result" => "success"));
}
示例10: throwJson
/**
* 抛出json回执信息
*
* @access public
* @param string $message 消息体
* @param string $charset 信息编码
* @return void
*/
function throwJson($message, $charset = NULL)
{
/** 设置http头信息 */
header('content-Type: application/json; charset=' . (empty($charset) ? 'UTF-8' : $charset), true);
echo json::encode($message);
/** 终止后续输出 */
exit;
}
示例11: rsp_err
function rsp_err($msg = '', $status = '400 Bad Request', $bt = null)
{
$rsp = array('message' => $msg);
if ($bt) {
$rsp['bt'] = $bt;
}
rsp_ok(json::pretty(array('error' => $rsp)), $status);
}
示例12: add
public static function add($file, $content)
{
$a = json::open($file);
if (is_array($a)) {
$a[] = $content;
return json::save($file, $a);
}
return false;
}
示例13: show
/**
* Allows the given item to be displayed again.
*
* @param int $id the item id
*/
public function show($id)
{
$item = model_cache::get("item", $id);
$msg = t("Displayed <b>%title</b> item", array("title" => html::purify($item->title)));
$this->_check_hide_permissions($item);
hide::show($item);
message::success($msg);
json::reply(array("result" => "success", "reload" => 1));
}
示例14: inicial
/**
* Método inicial do controle
*/
function inicial()
{
$this->entidade = $_GET;
$arNome = explode(' ', strtolower($this->entidade['entidade']));
$nome = array_shift($arNome);
$arNome = array_map("ucFirst", $arNome);
array_unshift($arNome, $nome);
$this->nomeEntidade = implode('', $arNome);
$this->nomeNegocio = "N{$this->nomeEntidade}";
$xml = array();
if (arquivo::legivel("{$this->nomeEntidade}/xml/entidade.xml")) {
$xml['entidade'] = simplexml_load_file("{$this->nomeEntidade}/xml/entidade.xml");
}
if (arquivo::legivel("{$this->nomeEntidade}/xml/pt_BR.xml")) {
$xml['inter'] = simplexml_load_file("{$this->nomeEntidade}/xml/pt_BR.xml");
}
$j = new json();
echo $j->pegarJson($xml);
}
示例15: star_only_off
public function star_only_off()
{
//$item = model_cache::get("item", $id);
access::verify_csrf();
$msg = t("Showing all items.");
//$this->_check_star_permissions($item);
star::star_only_off();
message::success($msg);
json::reply(array("result" => "success", "reload" => 1));
}