当前位置: 首页>>代码示例>>PHP>>正文


PHP functions::json_encode方法代码示例

本文整理汇总了PHP中functions::json_encode方法的典型用法代码示例。如果您正苦于以下问题:PHP functions::json_encode方法的具体用法?PHP functions::json_encode怎么用?PHP functions::json_encode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在functions的用法示例。


在下文中一共展示了functions::json_encode方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: run

 function run()
 {
     /**@var tf_sat $sat */
     $sat = core::module('sat');
     $site = $sat->get_current_site();
     $json_file = loader::get_public('assets/' . $site->domain . '.json');
     $last_mod = @filemtime($json_file);
     $tree_last_mod = 0;
     if ($last_mod) {
         $last_node = $sat->get_node_handle()->set_where('site_id = %d', $sat->get_current_site_id())->set_order('updated_at DESC')->load_first();
         $tree_last_mod = $last_node ? $last_node->updated_at : 0;
         core::dprint(__METHOD__ . ': cached');
         // uptodate
         if ($tree_last_mod <= $last_mod) {
             $this->renderer->set_ajax_answer(file_get_contents($json_file))->ajax_flush();
             return;
         }
     }
     core::dprint(__METHOD__ . ': fetch!');
     $tree = $sat->get_current_site_tree();
     $allowedKeys = array('title', 'url');
     array_walk($tree, function (&$v) use($allowedKeys) {
         $v = array_intersect_key($v, array_flip($allowedKeys));
     });
     $tree = array_values($tree);
     // cache
     file_put_contents($json_file, functions::json_encode($tree));
     $this->renderer->set_ajax_answer($tree)->ajax_flush();
 }
开发者ID:egregor-dev,项目名称:SatCMS,代码行数:29,代码来源:tree.php

示例2: as_json

 /**
  * Convert to json
  * @return string json
  */
 function as_json($fields = false, $assoc = false)
 {
     $out = array();
     if (!empty($this->items)) {
         foreach ($this->items as $id => $v) {
             $row = $v->as_json($fields);
             if ($assoc) {
                 $out[$id] = $row;
             } else {
                 $out[] = $row;
             }
         }
     }
     return functions::json_encode($out);
 }
开发者ID:egregor-dev,项目名称:SatCMS,代码行数:19,代码来源:collection.php

示例3: output_ajax

 /**
  * Triggers in ajax mode call
  * Template assign through: @see get_main_template()
  * called from @see core::shutdown
  */
 public function output_ajax($is_return = false)
 {
     /*
     //disabled in core
     if ($console = core::lib('console')) {
         $console->disable();
     }
     */
     $this->output_begin(array('in_ajax' => true));
     // output_ajax conflict in editor
     // @todo test this
     if (loader::in_ajax() === 'json') {
         $this->set_ajax_type('json');
     }
     if (core::in_editor()) {
         $this->output_editor();
     }
     $tpl = $this->get_main_template();
     if ($tpl) {
         $tpl = substr($tpl, 0, -4);
         // output_end will append .TPL
     }
     if (!$is_return && self::AJAX_JSON == @$this->ajax_answer['type']) {
         $this->content_type_header('application/json', 'utf-8');
     }
     /**
      * JSON answer
      */
     if (!empty($tpl) && self::AJAX_JSON == @$this->ajax_answer['type']) {
         // parse template, if any
         $buffer = $this->output_end($tpl, true);
         // output ajax json data
         $return = is_array($this->ajax_answer['data']) ? $this->ajax_answer['data'] : array();
         // if rendered with template
         if (isset($buffer)) {
             $return['data'] = $buffer;
         }
         // send message
         if (empty($tpl) && !empty($this->_message['message'])) {
             $return['message'] = $this->_message['message'];
         }
         echo json_encode($return);
     } elseif (empty($tpl)) {
         // allow prepared json
         echo self::AJAX_JSON == $this->ajax_answer['type'] ? is_string($this->ajax_answer['data']) ? $this->ajax_answer['data'] : functions::json_encode($this->ajax_answer['data']) : @$this->ajax_answer['data']['data'];
     } else {
         // plain output
         $this->output_end($tpl);
     }
 }
开发者ID:egregor-dev,项目名称:SatCMS,代码行数:55,代码来源:renderer.php


注:本文中的functions::json_encode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。