zoukankan      html  css  js  c++  java
  • php的CodeIgniter学习笔记(二)

    1,为CodeIgniter添加 Json功能。

    php5.2已经内置了json_encode, json_decode方法。

    但是,php 5.2以下的版本,并没有Json功能。加上这个功能也很简单:

    http://codeigniter.com/wiki/JSON_Helper/ 去这个地方下载json的实现。

    装上去后如果有错,请把json_helper.php里的两个方法改成:

     function json_encode($data = null)
      {
          $json = new Services_JSON();
      	if($data == null) return false;
      	return $json->encode($data);
      }
    
      function json_decode($data = null)
      {
          $json = new Services_JSON();
      	if($data == null) return false;
      	return $json->decode($data);
      }

    2,PHP常用的几个时间函数。。

    date() 返回时间字符串。

    mktime() 返回unix时间戳。

    strtotime() 返回Unix时间戳。

    time() 返回当前Unix时间戳。

    3,CodeIgniter 的一些常用查询。

            $this->db->select('page,year,month,day,count(ip) as visitorNum');
            $this->db->select_sum('totol_m');
            $this->db->group_by(array('page','year','month','day'));
            $where = array('page'=>$page,'year'=>$y,'month'=>$m);
            $this->db->where($where);
            $this->db->from('ipcount');
            $query = $this->db->get();
     
            $this->db->select('id, date_submission');
            $this->db->where('date_submission >',date('Y-m-d H:i:s',$start_date));
            $this->db->where('date_submission <',date('Y-m-d H:i:s',$end_date));
            $this->db->from('`mh_photos');
            $query = $this->db->get();
     
    4,让CodeIgniter能使用$_GET。
    $config['uri_protocol']    = "PATH_INFO";//在config.php里设置。
    config里的hooks.php添加以下内容:
     
    $hook['post_controller_constructor'] = array(
    		 	'function' => 'allow_query_string',
    		 	'filename' => 'allow_query_string.php',
    		 	'filepath' => 'hooks'
    		 );
     
    hooks里添加以下文件 : allow_query_string.php
    内容如下:
    <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
    
    /*
    	Function: allow_query_string
    	Overrides CIs default behaviour of destroying $_GET
    
    	Install:
    		Put this function in hooks/allow_query_string.php
    
    		Enable hooks in config/config.php
    		> $config['enable_hooks'] = TRUE;
    
    		Define the hook in config/hooks.php
    		> $hook['post_controller_constructor'] = array(
    		> 	'function' => 'allow_query_string',
    		> 	'filename' => 'allow_query_string.php',
    		> 	'filepath' => 'hooks'
    		> );
    */
    function allow_query_string() {
        parse_str($_SERVER['QUERY_STRING'], $_GET);
        $_CI =& get_instance();
        foreach ($_GET as $key=>$val) {
    		$_GET[$key] = $_CI->input->xss_clean($val);
    	}
    }

    其它这里有说了。。哈。

    大概是这样。。

    下图是用CodeIgniter,Json结合Flex弄的统计的界面。。

    image

  • 相关阅读:
    怎样使用 Apache ab 以及 OneAPM 进行压力測试?
    opencv之haar特征+AdaBoos分类器算法流程(三)
    分区函数Partition By的与row_number()的用法以及与排序rank()的用法详解(获取分组(分区)中前几条记录)
    REST API 调用 方法
    WebApi的安全性及其解决方案
    使用Topshelf创建Windows服务
    LINQ查询操作符之First、FirstOrDefault、Last、LastOrDefault、ElementAt、ElementAtOrDefault、Contains、Any、All、Count
    sqlbulkcopy 多表批量保存
    C#使用HttpWebRequest和HttpWebResponse上传文件示例
    C#模拟客户端发送数据示例
  • 原文地址:https://www.cnblogs.com/OtisBlog/p/1502335.html
Copyright © 2011-2022 走看看