浏览代码

add new fortune and add sort fortune

Hendrawan Kuncoro 12 年之前
父节点
当前提交
02df0947fa
共有 1 个文件被更改,包括 18 次插入2 次删除
  1. 18 2
      php-senthot/app/Lib/Action/BenchAction.class.php

+ 18 - 2
php-senthot/app/Lib/Action/BenchAction.class.php

@@ -1,5 +1,4 @@
 <?php
-// This class automatically generated by the System, for testing purposes
 class BenchAction extends Action {
 
    public function rawjson() {
@@ -30,7 +29,24 @@ class BenchAction extends Action {
    }
    public function rawfortunes() {
       $Fortunes = M('Fortune');
-      $this->data = $Fortunes->select();
+      $data = $Fortunes->select();
+
+      $data[] = array(
+            'id' => 0,
+            'message' => 'Additional fortune added at request time.'
+        );
+
+      usort($data, function($left, $right) {
+         if ($left['message'] === $right['message']) {
+            return 0;
+         } else if ($left['message'] > $right['message']) {
+            return 1;
+         } else {
+            return -1;
+         }
+      });
+
+      $this->data = $data;
       $this->display();
    }
 }