jQuery MiniUI,快速开发WebUI界面

PHP开发EXT应用框架 - PHP-EXT

    现在从事PHP网站开发的人员并不在少数,使用ExtJs的人更加不在少数,但很多PHP程序员并不熟悉Javascript,但又非常喜欢使用ExtJs.以前他们只能看着JAVA或者.NET的开发者可以使用服务器端的语言来写ExtJs,现在PHP中也有了类似的框PHP-EXT .

下面我们来看一下简单DataGrid的例子:

要实现上面的效果,不用写一句js代码.

<?php
/* 
 * @author Matthias Benkwitz
 * @website http://www.bui-hinsche.de
 */ 
set_include_path(get_include_path().PATH_SEPARATOR.realpath('../../library'));
include_once 'PhpExt/Javascript.php';
PhpExt_Javascript::sendContentType();
$httpHost = "http://".$_SERVER['HTTP_HOST'];
$docRoot = str_replace("\\","/",realpath($_SERVER['DOCUMENT_ROOT']));
$dir = str_replace("\\","/",realpath(dirname(__FILE__)."/.."));
$baseUrl = str_replace($docRoot,$httpHost,$dir);



include_once 'PhpExt/Ext.php';
include_once 'PhpExt/Data/SimpleStore.php';
include_once 'PhpExt/Data/ArrayReader.php';
include_once 'PhpExt/Data/JsonReader.php';
include_once 'PhpExt/Data/ScriptTagProxy.php';
include_once 'PhpExt/Data/FieldConfigObject.php';
include_once 'PhpExt/Data/StoreLoadOptions.php';
include_once 'PhpExt/Data/HttpProxy.php';
include_once 'PhpExt/Data/JsonStore.php';

include_once 'PhpExt/Toolbar/PagingToolbar.php';
include_once 'PhpExt/Grid/ColumnModel.php';
include_once 'PhpExt/Grid/ColumnConfigObject.php';
include_once 'PhpExt/Grid/GridPanel.php';


$PageSize = 10;


$changeRenderer = PhpExt_Javascript::functionDef("change","if(val > 0){
            return '<span style=\"color:green;\">' + val + '</span>';
        }else if(val < 0){
            return '<span style=\"color:red;\">' + val + '</span>';
        }
        return val;",array("val"));
$pctChangeRenderer = PhpExt_Javascript::functionDef("pctChange","if(val > 0){
            return '<span style=\"color:green;\">' + val + '%</span>';
        }else if(val < 0){
            return '<span style=\"color:red;\">' + val + '%</span>';
        }
        return val;",array("val"));


$reader = new PhpExt_Data_JsonReader();
$reader->setRoot("topics")
       ->setTotalProperty("totalCount")
       ->setId("id");
$reader->addField(new PhpExt_Data_FieldConfigObject("company"));
$reader->addField(new PhpExt_Data_FieldConfigObject("price",null,"float"));
$reader->addField(new PhpExt_Data_FieldConfigObject("change",null,"float"));
$reader->addField(new PhpExt_Data_FieldConfigObject("pctChange",null,"float"));
$reader->addField(new PhpExt_Data_FieldConfigObject("lastChange",null,"date","n/j h:ia"));
$reader->addField(new PhpExt_Data_FieldConfigObject("industry"));

// Store
$store = new PhpExt_Data_Store();
$store->setUrl($baseUrl.'/grid/json_exampledata.php')   
   ->setReader($reader)
   ->setBaseParams(array("limit"=>$PageSize));



// ColumnModel
$colModel = new PhpExt_Grid_ColumnModel();
$colModel->addColumn(PhpExt_Grid_ColumnConfigObject::createColumn("Company","company","company",160, null, null, true, false))
         ->addColumn(PhpExt_Grid_ColumnConfigObject::createColumn("Price","price",null,75,null,PhpExt_Javascript::variable("Ext.util.Format.usMoney"), true, true))
         ->addColumn(PhpExt_Grid_ColumnConfigObject::createColumn("Change","change",null,75,null,PhpExt_Javascript::variable('change'), null, true))
         ->addColumn(PhpExt_Grid_ColumnConfigObject::createColumn("% Change","pctChange",null,75,null,PhpExt_Javascript::variable('pctChange'), null, true))
         ->addColumn(PhpExt_Grid_ColumnConfigObject::createColumn("Last Updated","lastChange",null,85,null,PhpExt_Javascript::variable("Ext.util.Format.dateRenderer('m/d/Y')"), null, true))
         ->addColumn(PhpExt_Grid_ColumnConfigObject::createColumn("Industry","industry",null,85,null,null, true, true));

// Grid
$grid = new PhpExt_Grid_GridPanel();
$grid->setStore($store)
     ->setColumnModel($colModel)
     ->setStripeRows(true)
     ->setAutoExpandColumn("company")
     ->setHeight(350)
     ->setWidth(600)
     ->setTitle("Json Grid");


$paging = new PhpExt_Toolbar_PagingToolbar();
$paging->setStore($store)
       ->setPageSize($PageSize)
       ->setDisplayInfo("Topics {0} - {1} of {2}")
       ->setEmptyMessage("No topics to display");
$grid->setBottomToolbar($paging);
// Ext.OnReady -----------------------
echo PhpExt_Ext::onReady(
	$changeRenderer,
	$pctChangeRenderer,
	$store->getJavascript(false, "store"),
	$store->load(new PhpExt_Data_StoreLoadOptions(array(
			"start"=>0,"limit"=>$PageSize))
	),
	$grid->getJavascript(false, "grid"),
	$grid->render("grid-example")
);


?>

项目主页:
http://php-ext.quimera-solutions.com/

http://code.google.com/p/php-ext/