|
@@ -3,6 +3,7 @@
|
|
namespace app\controllers;
|
|
namespace app\controllers;
|
|
|
|
|
|
use Yii;
|
|
use Yii;
|
|
|
|
+use yii\helpers\Html;
|
|
use yii\web\Controller;
|
|
use yii\web\Controller;
|
|
|
|
|
|
class SiteController extends Controller
|
|
class SiteController extends Controller
|
|
@@ -29,7 +30,7 @@ class SiteController extends Controller
|
|
$arr = $statement->bindValue(':id',mt_rand(1, 10000))->queryOne();
|
|
$arr = $statement->bindValue(':id',mt_rand(1, 10000))->queryOne();
|
|
} else {
|
|
} else {
|
|
if ($queries > 500) $queries = 500;
|
|
if ($queries > 500) $queries = 500;
|
|
- elseif ($queries < 0 ) $queries = 1;
|
|
|
|
|
|
+ elseif ($queries <= 0 ) $queries = 1;
|
|
// Create an array with the response string.
|
|
// Create an array with the response string.
|
|
$arr = array();
|
|
$arr = array();
|
|
// For each query, store the result set values in the response array
|
|
// For each query, store the result set values in the response array
|
|
@@ -43,8 +44,30 @@ class SiteController extends Controller
|
|
}
|
|
}
|
|
|
|
|
|
public function actionFortunes() {
|
|
public function actionFortunes() {
|
|
|
|
+ // Test Data
|
|
|
|
+// $arr = [
|
|
|
|
+// 11=>'<script>alert("This should not be displayed in a browser alert box");</script>',
|
|
|
|
+// 4=>'A bad random number generator: 1, 1, 1, 1, 1, 4.33e+67, 1, 1, 1',
|
|
|
|
+// 5=>'A computer program does what you tell it to do, not what you want it to do.',
|
|
|
|
+// 2=>'A computer scientist is someone who fixes things that aren\'t broken.',
|
|
|
|
+// 8=>'A list is only as strong as its weakest link. — Donald Knuth',
|
|
|
|
+// //0=>'Additional fortune added at request time.',
|
|
|
|
+// //0=>'Additional fortune added at request time.',
|
|
|
|
+// 3=>'After enough decimal places, nobody gives a damn.',
|
|
|
|
+// 7=>'Any program that runs right is obsolete.',
|
|
|
|
+// 10=>'Computers make very fast, very accurate mistakes.',
|
|
|
|
+// 6=>'Emacs is a nice operating system, but I prefer UNIX. — Tom Christaensen',
|
|
|
|
+// 9=>'Feature: A bug with seniority.',
|
|
|
|
+// 1=>'fortune: No such file or directory',
|
|
|
|
+// 12=>'フレームワークのベンチマーク'
|
|
|
|
+// ];
|
|
|
|
+// foreach($arr as $k=>$v) {
|
|
|
|
+// Yii::$app->db->createCommand('insert into Fortune (id,message) values (:id,:message)',[':id'=>$k,':message'=>$v])->execute();
|
|
|
|
+// }
|
|
|
|
+
|
|
|
|
+
|
|
$arr = Yii::$app->db->createCommand('select id, message from Fortune')->queryAll();
|
|
$arr = Yii::$app->db->createCommand('select id, message from Fortune')->queryAll();
|
|
- $arr[0] = 'Additional fortune added at request time.';
|
|
|
|
|
|
+ $arr[] = ['id'=>0,'message'=>'Additional fortune added at request time.'];
|
|
asort($arr);
|
|
asort($arr);
|
|
header("Content-Type: text/html; charset=utf-8");
|
|
header("Content-Type: text/html; charset=utf-8");
|
|
echo <<<EOM
|
|
echo <<<EOM
|
|
@@ -60,10 +83,10 @@ class SiteController extends Controller
|
|
<th>message</th>
|
|
<th>message</th>
|
|
</tr>
|
|
</tr>
|
|
EOM;
|
|
EOM;
|
|
- foreach ( $arr as $id => $fortune ) {
|
|
|
|
|
|
+ foreach ( $arr as $val ) {
|
|
echo '<tr>';
|
|
echo '<tr>';
|
|
- echo '<td>'.$id.'</td>';
|
|
|
|
- echo '<td>'.htmlspecialchars($fortune, ENT_QUOTES, 'utf-8').'</td>';
|
|
|
|
|
|
+ echo '<td>'.$val['id'].'</td>';
|
|
|
|
+ echo '<td>'.Html::encode($val['message']).'</td>';
|
|
echo '</tr>';
|
|
echo '</tr>';
|
|
}
|
|
}
|
|
echo <<<EOM
|
|
echo <<<EOM
|
|
@@ -76,7 +99,7 @@ EOM;
|
|
|
|
|
|
public function actionUpdates($queries = 1) {
|
|
public function actionUpdates($queries = 1) {
|
|
if ($queries > 500) $queries = 500;
|
|
if ($queries > 500) $queries = 500;
|
|
- elseif ($queries < 0 ) $queries = 1;
|
|
|
|
|
|
+ elseif ($queries <= 0 ) $queries = 1;
|
|
$selectCommand = Yii::$app->db->createCommand('select randomNumber from World where id = :id');
|
|
$selectCommand = Yii::$app->db->createCommand('select randomNumber from World where id = :id');
|
|
$updateCommand = Yii::$app->db->createCommand('update World set randomNumber = :num where id = :id');
|
|
$updateCommand = Yii::$app->db->createCommand('update World set randomNumber = :num where id = :id');
|
|
$arr = [];
|
|
$arr = [];
|