Archive for the 'PHP' Category

MARS FRAMEWORK 备忘

星期一, 五月 16th, 2011

路径结构

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# /configs                                  全局config路径
# /libs                                 全局库路径
# /locales                                  全局locales路径
# /modules                              模块路径
# /modules/index                            默认模块,module=default
# /modules/user1                            自定义模块,module=user1
# /modules/user1/app1                       自定义模块(user1)下的app1,app=app1
# /modules/user1/app1/controller                自定义模块(user1)下的app1,controller路径
# /modules/user1/app1/controller/controller1.php    自定义模块(user1)下的app1的controller1
# /modules/user1/app1/views                 自定义模块(user1)的app1下的view路径
# /modules/user1/app1/views/controler1      自定义模块(user1)下app1的controller=controller1的view路径
# /modules/user1/configs                    自定义模块(user1)的configs路径
# /modules/user1/bootstrap.php              自定义模块(user1)的启动文件
# /public                                   document_root
# /public/index.php                         入口
# /tests                                    测试程序
# /bootstrap.php                            全局启动路径

/public/.htaccess

1
2
3
4
5
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

/public/index.php

1
<!--?php include("../bootstrap.php"); $route = Mars_Router::getInstance(); $route--->initialize();

Mars_BaseController

所有controller的基类,action响应用func_action(void)获取

4种渲染方法,通过$controller->frontend设置:

  1. HTML
  2. JSON
  3. TEXT(PLAINTEXT)
  4. XML

HTML View(默认渲染方式)

默认frame view使用/views/frame.phtml,默认view使用该模块/app/views/controller/action.phtml

如要使用特殊的frame view或view请用
$controller->_frameView
$controller->_view
进行设置

JSON View
相关变量$controller->return是返回数据,$controller->success标示是否成功
如:

1
2
3
4
5
6
function test_action()
{
    $this->frontend = Mars_FrontEnd::JSON;
    $this->return = array(1, 2);
    $this->success = true;
}

返回:

1
{"success":true,"data":[1,2]}

TEXT View

1
2
3
4
5
function text_action()
{
    $this->frontend = Mars_FrontEnd::TEXT;
    $this->return = "hello world";
}

返回

1
hello world

XML View

1
2
3
4
5
function xml_action()
{
    $this->frontend = Mars_FrontEnd::XML ;
    $this->return = array(1,2,3);
}

返回:

1
2
<?xml version="1.0" encoding="UTF-8"?>
<data><foobar>1</foobar><foobar>2</foobar><foobar>3</foobar></data>

Mars_BaseController->cache
cache是符合memcache类的实例,将会存储output结果,在缓存存在时直接输出缓存
cache_key由uri及$_GET中的参数组成,如$_GET中有__refresh参数则会刷新缓存,或controller中有一成员变量标示$action.”_refresh”=true/false可以强制不使用或使用缓存。

Mars_EventManager 事件处理

插入事件点(Event Point),如:

1
Mars_EventManager::register("ACTION_BEGIN", new Mars_Event(Mars_Event::ACTION_BEGIN, $this));

在bootstrap.php中添加事件侦听

1
Mars_EventManager::getInstance()->addEventListener(Mars_Event::BEGIN, callback_function);

callback_function有一个参数,即Mars_Event

默认支持以下事件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
    # router begins
    const BEGIN             = "BEGIN";
    # router ends
    const END               = "END";
    # controller class not found
    const CLASS_NOT_FOUND   = "CLASS_NOT_FOUND";
    # controller's action not found
    const ACTION_NOT_FOUND  = "ACTION_NOT_FOUND";
    # controller's action begins
    const ACTION_BEGIN      = "ACTION_BEGIN";
    # controller's action ends
    const ACTION_END        = "ACTION_END";
    # render view begins
    const RENDER_BEGIN      = "RENDER_BEGIN";
    # render view ends
    const RENDER_END        = "RENDER_END";
    # launch begins
    const LAUNCH_BEGIN      = "LAUNCH_BEGIN";
    # launch ends
    const LAUNCH_END        = "LAUNCH_END";
    # view output begin
    const FILTER_OUTPUT     = "FILTER_OUTPUT";

前置和后置过滤器

1
2
3
4
5
6
7
8
9
10
11
function test_filter($c, $t, $in, $out)
{
    return str_replace("A", "BB", $c);
}
Mars_PostFilter::getInstance()->register("test_filter");

function test_prefilter($param)
{
    $_GET['xxxx'] = $param;
}
Mars_PreFilter::getInstance()->register(array('function'=>'test_prefilter', 'params'=>array('a')));

win7下安装zend studio 5.5

星期一, 五月 17th, 2010

装了windows 7,发现普通模式不兼容zendstudio,又装了zendstudio 7,发现那个难用啊,晕死,下面是win7上安装
zendstudio 5.5的步骤

01、下载并安装最新版本的 JRE for Windows: http://java.com/en/download/manual.jsp

02、使用WINRAR解压 Zend Studio 5.5.1.exe

03、 进入解压后的文件夹 Zend Studio 5.5.1Windows(下面简称A文件夹) ,将resource目录下的jre文件夹重命名为jre.back(或其他名称都可)

04、复制 C:Program Files (x86)Javajre6到第三步中的目录,并将jre6重命名为jre

05、执行安装 A文件夹下的 Zend Studio 5.5.1.exe

06、安装完成后将 A文件夹 下 resource 目录中的jre.back文件夹复制到Zend Studio 的安装目录中,

07、重命名安装目录中的 jre 文件夹为 jre6

08、重命名安装目录中的 jre.back 文件夹为 jre

09、在ZendStudio图标上点击右键/属性/兼容性 设置兼容模式为 Vista

10、启动Zend Studio