用户
 找回密码
 入住 CI 中国社区
搜索
查看: 6914|回复: 9
收起左侧

翻译了TinyAjax

  [复制链接]
发表于 2010-4-12 22:18:16 | 显示全部楼层 |阅读模式
本帖最后由 snllll 于 2010-4-12 22:28 编辑

源地址:http://codeigniter.com/wiki/TinyAjax/
自己需要,就顺手给贴过来了,谈不上翻译不翻译的,因为太简单了。需要的看下:

TinyAjax is a small php5 library that allows you to easily add AJAX-functionality to existing pages and create new AJAX-enabled pages with just a few lines of code.
TinyAjax是一个小巧的php5的函数库,它可以使你非常方便的用很少几行代码添加AJAX到已经已经存在的页面,并且创建一个AJAX交互的页面。
* Put the include/TinyAjax.php and TinyAjaxBehavior.php into system/application/libraries/
* Put the include/TinyAjax.js into the “top-level directory”/js directory
* Put the following code into system/application/init/init_tinyajax.php
将include/TinyAjax.php和TinyAjaxBehavior.php放到system/application/libraries/下
将the include/TinyAjax.js放置在 "顶层目录"/js下——重要
将以下代码拷贝到system/application/init/init_tinyajax.php保存

<?php if(!defined('BASEPATH')) exit('No direct script access aellowed');

if (!
class_exists('TinyAjax'
))
{
    define
('TINYAJAX_PATH', BASEPATH.'application/libraries/'
);
    require_once(
TINYAJAX_PATH.'TinyAjax'.EXT
);
}

$obj
=& get_instance
();
$obj->tinyajax = new TinyAjax
();
$obj->tinyajax->setScriptPath('../../js'
);
$obj->tinyajax->setRequestType('post'
);

?>


————————————————————————————
应用教程:Example of use
A simple multiplication example. Here is the Controller.

一个简单的乘法运算的例子,这是控制器的代码:
————————————————————————————
<?php
class Ajax extends Controller {
   
   
function Ajax()
   
{
        parent
::Controller();
        
$this->load->library('tinyajax');
   
}   

   
function ajax_multiply($x, $y)
   
{
        
return $x*$y;
   
}        
           
   
function multiply()
   
{   
        $this
->tinyajax->showLoading();
        
$this->tinyajax->exportFunction("ajax_multiply", array("first_id", "second_id"), "#third_id", $this);
        
        
$this->tinyajax->process();
        
$this->load->view('ajax_multiply');
   
}   
}
?>

————————————————————————————
视图:

And here is the ajax_multiply.php views file:
————————————————————————————
<html>
<head>
<? $this->tinyajax->drawJavaScript(false,true); ?>
</head>
<body>
    Multiply乘法:<br>
    <input type="text" id="first_id" value="2"> *
    <input type="text" id="second_id" value="3"> =
    <input type="text" id="third_id" value="">
    <input type="button" value=" * ">
</body>
</html>
————————————————————————————
Example with Behavior
Add this code to the controller: 将这些代码将入到控制器中
————————————————————————————
function ajax_multiplyb($x, $y)
    {
      $res = $x * $y;
      $res_text = "Multiplying $x and $y results in $res{正在计算的$x和$y的结果是$res}";
   
      $tab = new TinyAjaxBehavior();
      $tab->add(TabSetValue::getBehavior("third_id", $res));
      $tab->add(TabInnerHtml::getBehavior("result_div", $res_text));
      return $tab->getString();
   }

    function multiplyb()
    {   
        $this->tinyajax->showLoading();
        $this->tinyajax->exportFunction("ajax_multiplyb", array("first_id", "second_id"), null, $this);
        
        $this->tinyajax->process();
        $this->load->view('ajax_multiplyb');
    }

————————————————————————————
And the views file ajax_multiplyb.php look like this:

————————————————————————————
<html>
<head>
<? $this->tinyajax->drawJavaScript(false,true); ?>
</head>
<body>
    Multiply:<br>
    <input type="text" id="first_id" value="2"> *
    <input type="text" id="second_id" value="3"> =
    <input type="text" id="third_id" value="">
    <input type="button" value=" * ">
    <br/>
    <div id="result_div">&nbsp;</div>
</body>
</html>

评分

参与人数 1威望 +5 收起 理由
Hex + 5 我很赞同

查看全部评分

 楼主| 发表于 2010-4-16 00:02:23 | 显示全部楼层
HEX老大谬赞了~~感动中
发表于 2010-6-24 10:44:56 | 显示全部楼层
哪里下载?
发表于 2010-12-17 23:15:58 | 显示全部楼层
Mark一下~~
发表于 2011-5-7 16:04:08 | 显示全部楼层
good job!
发表于 2011-5-12 19:48:05 | 显示全部楼层

链接失效了!!
发表于 2011-5-13 16:35:39 | 显示全部楼层
看起来像好东西
发表于 2011-10-21 09:31:02 | 显示全部楼层
这个东西跟直接用JQUERY写JS相比,有什么优势呢?
发表于 2011-10-27 09:02:19 | 显示全部楼层
baiyuxiong 发表于 2011-10-21 09:31
这个东西跟直接用JQUERY写JS相比,有什么优势呢?

玩玩还不错。

真正要生产,还是js归js,php归php好。
发表于 2012-1-11 14:01:38 | 显示全部楼层
remark下

本版积分规则