CI框架整合yar
第一步:在CI框架中libraries目录下建立yar.php 文件
内容:
<?php
/**
* yar 接口
*/
class Yar
{
/**
* 构造函数
*
* @return void
* @throws Exception
* @access public
*/
public function __construct ()
{
}
/**
* 接口
*
* @return void
* @throws Exception
* @access public
*/
public function yarApi ( array $condition )
{
$default = array(
// 服务器地址 'url'=>'http://admin.com/rpc/',
'url'=>'http://localhost/rpc/',
'model'=>'',//model名称
);
$condition = array_merge($default,$condition);
return new Yar_Client("{$condition['url']}{$condition['model']}");
} }
2.在配置文件中添加yar让CI 自动加载
config目录下autoload.php文件
修改:
$autoload['libraries'] = array('yar');
3.在api服务端也是CI框架建立Rpc.php控制器
内容:
<?php
/**
* rpc接口
* Created by PhpStorm.
* User: hteen
* Date: 16/6/24
* Time: 下午4:39
*/
class Rpc extends CI_Controller { public function index( $model ){ if (!$this->_auth())
show_error('error',); try {
$this->load->model($model);
}catch ( Exception $e ){ log_message('error','rpc load model error , model name is '.$model);
show_error('load model error',);
} $service = new Yar_Server( new $model );
$service->handle();
} /**
* 权限认证
* @author hteen
* @return bool
*/
private function _auth(){ // TODO:RPC权限验证
return true;
} }
4.使用yar
在控制器中使用yar 访问api接口
例如:
//实例化对象
$ActivityModel = $this->yar->yarApi(['model' => 'ActivityModel']);
//调用方法
$active_info = $ActivityModel->getinfo($id);
CI框架整合yar的更多相关文章
- Ci框架整合smarty模板引擎
Ci框架整合smarty模板引擎 备注:下载smarty时,最好选择2.6版本,其他测试有坑,ci可以是2.2或其他 大体思路:将smarty封装成ci框架的一个类,然后重新配置一下smarty,这样 ...
- CI框架整合UEditor编辑器上传功能
最近项目中要使用到富文本编辑器,选用了功能强大的UEditor,接下来就来讲讲UEditor编辑器的上传功能整合. 本文UEditor版本:ueditor1_4_3_utf8_php版本 第一步:部署 ...
- CI框架整合微信公共平台接口
#CI框架控制器 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); /*** CI框架整合微信 ...
- 在CI框架中的配置整合amfphp
之前做的项目用到CI框架和amfphp的整合,主要用于php与flex的交互,在此做一下记录: 一. 安装CI框架: 1. 搭建PHP运行环境,本人在WIN7下用WAMP作测试,安装目录:d:/wa ...
- ci框架与smarty的整合
ci框架与smarty的整合 来源:未知 时间:2014-10-20 11:38 阅读数:108 作者:xbdadmin [导读] Ci 和 smarty 的完美结合 Ci 结合 sma ...
- **【ci框架】精通CodeIgniter框架
http://blog.csdn.net/yanhui_wei/article/details/25803945 一.大纲 1.codeigniter框架的授课内容安排 2.codeigniter框架 ...
- CI框架大纲总结
一.大纲 1.codeigniter框架的授课内容安排 2.codeigniter框架的简介 |-----关于框架的概念 |-----使用CI框架的好处 |-----为什么选择CI框架 3.codei ...
- php ci框架中载入css和js文件失败的原因及解决方法
在将html页面整合到ci框架里面的时候,载入css和js失败. 原因是ci框架是入口的框架 对框架中文件的全部请求都须要经过index.php处理完毕,当载入外部的css和js文件的时候要使 用ba ...
- RabbitMQ与Spring的框架整合之Spring Boot实战
1.RabbitMQ与Spring的框架整合之Spring Boot实战. 首先创建maven项目的RabbitMQ的消息生产者rabbitmq-springboot-provider项目,配置pom ...
随机推荐
- 解决Windows下网络原因Composer安装失败问题
由于Composer镜像都在国外,所以直接在官网下载Windows Installer后安装很多情况下是无法成功安装的. 解决办法: 1,将php添加到系统环境变量,并开启openssl扩展. 2,点 ...
- UDP server & client
Server: import java.io.IOException; import java.net.DatagramPacket; import java.net.DatagramSocket; ...
- Opennms 问题整理
1.网页时间显示不正确,需要修改:bin/opennms: 添加:MANAGER_OPTIONS="$MANAGER_OPTIONS -Duser.timezone=Asia/Shangha ...
- JSP中文乱码总结
大家在JSP的开发过程中,经常出现中文乱码的问题,可能一至困扰着大家,现把JSP开发中遇到的中文乱码的问题及解决办法写出来供大家参考.首先了解一下Java中文问题的由来: Java的内核和class文 ...
- 论文阅读(Xiang Bai——【arXiv2016】Scene Text Detection via Holistic, Multi-Channel Prediction)
Xiang Bai--[arXiv2016]Scene Text Detection via Holistic, Multi-Channel Prediction 目录 作者和相关链接 方法概括 创新 ...
- asp.net MVC3 无法打开项目文件“E:\我们的项目\Project\HeatingMIS.Web\HeatingMIS.Web.csproj”。此安装不支持该项目类型。
在vs中打开mvc3项目,虽然装了mvc3,但是还是会遇到莫名其妙的错误,这是我在做开发的时候遇到的一个问题,附带解决方案,和大家分享一下 问题描述:无法打开项目文件“E:\我们的项目\Project ...
- node上截取图片工具 images(node-images)
我们经常会遇到服务器上传的图片进行裁剪或者增加logo等等一些操作,在node平台上该如何实现呢? 看到大家都在使用"gm"这个工具,功能很强大,但是在Windows平台上简直就是 ...
- Python数据结构与算法设计总结篇
1.Python数据结构篇 数据结构篇主要是阅读[Problem Solving with Python]( http://interactivepython.org/courselib/static ...
- Time crumbles things; everything grows old under the power of Time and is forgotten through the lapse of Time
Time crumbles things; everything grows old under the power of Time and is forgotten through the laps ...
- 如何用Java代码列出一个目录下所有的文件?
目录文件夹 File file=new File("H:\\"); for(File temp:file.listFiles()){//Java5的新特性之一就是增强的for循环. ...