码迷,mamicode.com
首页 > 其他好文 > 详细

Restler 使用CI的ActiveRecord

时间:2015-02-14 00:51:54      阅读:168      评论:0      收藏:0      [点我收藏+]

标签:

由于工作中,我们小组(3个人),我经验多一点点点,当时需要重新架构我写的API,我无意了解到Restful对android比较友好.当时找到了Restler,DB在前文提到是使用Respect/Relational,而我们的表的ID不是一定叫"id",导致写接口的同事无法进行下去,最后决定用Codeigniter Rest server来处理接口,用Restler写的API一直搁置到上上个礼拜,我研究了一下Restler使用Codeigniter(以下简称为:CI)的ActiveRecord,我提供的是一个案例

 我项目的目录是:

技术分享

vendor下的activeRecord是Codeigniter中的

 

<?php
namespace v1;

class Base {
    public $re_array = array(‘state‘=>0,‘msg‘=>‘No Result‘);
    //put your code here
    public $db;
    function __construct() {
       include_once "./vendor/activeRecord/active_init.php";
       $this->db = $db;
    }

    
}

?>

使用:

<?php
namespace v1;
/**
 * Description of Logo
 *
 * @author wakasann
 */
class Logo extends Base{
    //put your code here
    
    function __construct(){
            parent::__construct();
    }

    /**
    * 获取App Logo
    * 
    * 获取App 使用的Logo
    * 
    * @param string $username api用户名
    * @param string $password api密钥
    * @return string
    */
    public function index($username,$password){
        
        $query = $this->db->get("wakasann_config");
        $result = $query->row_array();
        $query->free_result();
        if(empty($result[‘logo‘])){
            $this->re_array[‘state‘] = 0;
            $this->re_array[‘msg‘] = "Please upload App Logo";
            return $this->re_array;
        }else{
            $this->re_array[‘state‘] = 1;
            $this->re_array[‘msg‘] = $result[‘siteurl‘].‘/Tpl/Index/res/images/‘.$result[‘logo‘];
            return $this->re_array;
        }
        
        
        
    }

}

原理是,我们的控制器继承了Base类,在我们的控制器里面,可以和在CI中写ActiveRecord一样,CURD都可以,happy coding!


 

由于时间关系,codeigniter 独立出来的github下载地址,我暂时忘记了,日后再补上!

 

Restler 使用CI的ActiveRecord

标签:

原文地址:http://www.cnblogs.com/fsong/p/4201937.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!