Browse Source

765, fixed sorting function.

Sort was sorting by index instead
of by message, fixed.
James Yen 11 years ago
parent
commit
6bd0bfaae9

+ 9 - 1
php-yii2/app/controllers/SiteController.php

@@ -43,6 +43,12 @@ class SiteController extends Controller
         return $this->resJson($arr);
     }
 
+    private static function cmp($a, $b) {
+
+	return ($a["message"] < $b["message"]) ? -1 : 1;
+
+    }
+
     public function actionFortunes() {
         // Test Data
 //        $arr = [
@@ -68,7 +74,9 @@ class SiteController extends Controller
 
         $arr = Yii::$app->db->createCommand('select id, message from Fortune')->queryAll();
         $arr[] = ['id'=>0,'message'=>'Additional fortune added at request time.'];
-        asort($arr);
+
+	usort($arr, array($this, 'cmp'));	       
+
         header("Content-Type: text/html; charset=utf-8");
         echo <<<EOM
             <!DOCTYPE html>

+ 1 - 1
php-yii2/app/index.php

@@ -14,7 +14,7 @@ $config = [
     'components' => [
         'db' => [
             'class' => 'yii\db\Connection',
-            'dsn' => 'mysql:host=localhost;dbname=hello_world',
+            'dsn' => 'mysql:host=127.0.0.1;dbname=hello_world',
             'username' => 'benchmarkdbuser',
             'password' => 'benchmarkdbpass',
             'charset' => 'utf8',

+ 1 - 1
php-yii2/deploy/nginx.conf

@@ -37,7 +37,7 @@ http {
         listen       8080;
         server_name  localhost;
 
-        root /home/ubuntu/FrameworkBenchmarks/php-yii2/app;
+        root /home/tfb/FrameworkBenchmarks/php-yii2/app;
         index  index.php;
 
         location / {