Browse Source

Codeigniter fortune testcase

Skamander 12 years ago
parent
commit
f09aa1d171

+ 25 - 0
php-codeigniter/application/controllers/bench.php

@@ -28,4 +28,29 @@ class Bench extends CI_Controller {
             ->set_content_type('application/json')
             ->set_output(json_encode($worlds));
     }
+
+    public function fortunes() {
+        $fortunes = $this->db
+            ->query('SELECT * FROM Fortune')
+            ->result_array();
+
+        $fortunes[] = array(
+            'id' => 0,
+            'message' => 'Additional fortune added at request time.'
+        );
+
+        usort($fortunes, function($left, $right) {
+            if ($left['message'] === $right['message']) {
+                return 0;
+            } else if ($left['message'] > $right['message']) {
+                return 1;
+            } else {
+                return -1;
+            }
+        });
+
+        $this->load->view('fortunes', [
+            'fortunes' => $fortunes
+        ]);
+    }
 }

+ 25 - 0
php-codeigniter/application/views/fortunes.php

@@ -0,0 +1,25 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="utf-8">
+    <title>Welcome to CodeIgniter</title>
+</head>
+<body>
+
+<table>
+    <tr>
+        <th>id</th>
+        <th>message</th>
+    </tr>
+
+    <?php foreach($fortunes as $fortune): ?>
+        <tr>
+            <td><?php echo $fortune['id']; ?></td>
+            <td><?php echo htmlspecialchars($fortune['message'], ENT_QUOTES, "UTF-8", false); ?></td>
+        </tr>
+    <?php endforeach; ?>
+
+</table>
+
+</body>
+</html>

+ 1 - 0
php-codeigniter/benchmark_config

@@ -11,6 +11,7 @@
       "setup_file": "setup",
       "db_url": "/index.php/bench/db",
       "query_url": "/index.php/bench/db/",
+      "fortune_url": "/index.php/bench/fortunes",
       "port": 8080,
       "sort": 63
     }

+ 1 - 1
php-codeigniter/index.php

@@ -18,7 +18,7 @@
  * NOTE: If you change these, also change the error_reporting() code below
  *
  */
-	define('ENVIRONMENT', 'development');
+	define('ENVIRONMENT', 'production');
 /*
  *---------------------------------------------------------------
  * ERROR REPORTING