如果我不能死在一万个敌人的包围中,那就让我死在一万个美女的怀抱中吧
kohana
kohana中使用PHPRPC
Nov 13th
kohana版本: 2.34
PHPRPC介绍: PHPRPC
以下是实现kohana 使用 PHPRPC的具体实例,已经应用在一具体的项目中。功能不算强大,算是抛砖引玉吧。
Library 中 Rpc.php
<?php defined('SYSPATH') OR die('No direct access allowed.');
class RPC_Core {
private static $instance;
private static $data;
private static $server;
private $phprpc;
public static function instance()
{
if (!isset(self::$instance))
{
$class = __CLASS__;
self::$instance = new $class;
}
return self::$instance;
}
public function __construct()
{
//self::$server = "http://172.16.7.5";
$this->phprpc = TRUE;
$this->phprpc = FALSE;
self::$server = "http://site.fj";
}
public function __call($name, $args){
$class = $name;
$method = $args[0];
$args = array_slice($args,1);
if($this->phprpc)
{
require_once(MODPATH.'phprpc/phprpc_client.php');
$client = new PHPRPC_Client(self::$server.'/server/data/'.$class.'/'.$method);
return $client->{$method}($args);
}else{
$class = 'As_'.$class;
$class = new $class;
return $class->{$method}($args);
}
}
}
服务器上Controllers中的 server.php
<?php defined('SYSPATH') OR die('No direct access allowed.');
class Server_Controller extends Controller {
public function data($class)
{
$method = $this->uri->segment(4);
require_once(MODPATH.'phprpc/phprpc_server.php');
$server = new PHPRPC_Server();
$class = 'As_'.$class;
$server->add($method , new $class);
$server->start();
}
}
服务器端事物处理文件 Library 中 As_user.php
<?php defined('SYSPATH') OR die('No direct access allowed.');
class As_user_Core {
public function hello($name)
{
return 'hello world '.kohana::debug($name);
}
public function test()
{
return '-m-';
}
}
客户端测试Controllers 代码
public function test()
{
echo 'rpc test ...................................<br/>';
$rpc = Rpc::instance();
echo $rpc->user('hello',$class='class',$name='1');
}
kohana3 tips: current uri
Oct 16th
完全版本(带GET参数):
$current_uri = URL::site($this->request->uri).'?'.http_build_query($_GET, '&');
干净版本:
$current_uri = URL::site($this->request->uri);
kohana2开发环境简单部署
Apr 6th
在这我将介绍下用kohana框架开发前一些准备工作,已经如何部署kohana到你的开发环境中。
步骤如下:
- 搭建 lamp环境
- 设置mod rewrite 模块
- 设置虚拟主机
- 设置kohana框架
我的环境如下:
- os: windows xp sp2
- lamp:wampserver 2.o
- konana: v2.3
步骤如下:
1.安装 wampserver
(安装文档请查看官方文档,不详细介绍)
2.设置mod rewrite
使用wampserver相对比较简单:
- 启动wamp server
- 点击系统小托盘中的wamp server 图标 选择apache->apache modules
- 将rewrite_module打钩(也可以自行选择自己需要的相关modules)
- 重新启动wamp server中的所有服务,使改动生效
3.设置自己的虚拟主机
1.点击系统托盘中的wamp server 图标 选择apache http.conf 这个文件,用编辑器打开
在文件底部添加:
NameVirtualHost *:80
ServerName www.kohana.fj
DocumentRoot D:wampwwwkohana
创建wampwwwkohana这个文件夹,重启apache生效
2.在系统hosts文件中添加 www.kohana.fj
hosts文件路径:C:WINDOWSsystem32driversetchosts
在hosts最后一行添加
127.0.0.1 www.kohana.fj
重现打开一个浏览器测试www.kohana.fj是否生效
4.设置kohana框架
1.解压kohana框架的所有文件到kohana这个文件夹中,目录结构如下:
kohana
—-appliaction
—-system
—-modules
—-index.php
—-.htaccess
2.修改kohana中的一些设置
2.1 .htaccess中修改为:
# Installation directory
RewriteBase /
2.2 application/config/config.php中修改为
$config['index_page'] = '';
这样,在你的开发环境中就可以用
http://www.kohana.fj/control/method/来访问你的kohana项目,url中不用添加index.php。
至此,kohana的简单开发环境部署完成。