Restler 使用CI的ActiveRecord

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

 我项目的目录是:

Restler 使用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下载地址,我暂时忘记了,日后再补上!

 

我上传到自己的github仓库,下载链接:https://github.com/wakasann/alone-activerecode

 

你可能感兴趣的:(ActiveRecord)