ExtJS4学习笔记 PHP代码

笔者在ExtJS4学习笔记原文中使用的服务器端代码是ASP的,我把它转成了PHP的。方便PHP的爱好者使用。代码如下:

<? 
//header('Cache-Control: no-cache, must-revalidate'); 
//header('Content-type: application/json');

//返回JSON数据,自定义一些测试数据。。
//这里的参数与EXT3.x相同,区别在于排序字段和排序方式使用了新的属性。
//由于这里是测试数据,接收的参数只用到了start,limit。sorts和dir在实际操作过程中,将之加入SQL的ORDER BY里即可。
$start = empty($_REQUEST["start"])?'':$_REQUEST["start"]; 
$limit = empty($_REQUEST["limit"])?'':$_REQUEST["limit"]; 

if ( $start == "" ) 
	$start = 0;

if ( $limit == "" ) 
	$limit = 50; 

$sorts = empty($_REQUEST["sort"])?'':$_REQUEST["sort"]; 
$dir = empty($_REQUEST["dir"])?'':$_REQUEST["dir"]; 

if ( $sorts != '' )
	$sorts = str_replace("'", "", trim($sorts)); 
	
if ( $dir != '' )
	$dir = str_replace("'", "", trim($dir)); 

$counts = 300; 
//注意,这里的counts相当于Rs.RecordCount,也就是记录总数。

$Ls = $start+$limit; 

if ( $Ls >= $counts ){
	$Ls = $counts;
} 

echo("{");
echo("\"total\":");
echo("\"".$counts."\",");
echo("\"items\":["); 

for ( $i=$start+1; $i<=$Ls; $i=$i+1 ) {
  echo("{");
  echo("\"title\":\"newstitle".$i."\"");
  echo(",");
  echo("\"author\":\"author".$i."\"");
  echo(",");
  echo("\"hits\":\"".$i."\"");
  echo(",");
  echo("\"addtime\":\"".time()."\"");
  echo("}");
  
  if ( $i < $Ls ) {
    echo(","); 
  } 
}

echo("]}");

?>
affiliate_link
Share this Post:
Digg Google Bookmarks reddit Mixx StumbleUpon Technorati Yahoo! Buzz DesignFloat Delicious BlinkList Furl

No Responses to “ExtJS4学习笔记 PHP代码”

Leave a Reply:

Name (required):
Mail (will not be published) (required):
Website:
Comment (required):
XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>