以前都是靜靜地在看着別人的博客,從今天開始也下筆留下點東西吧,隨便記錄下工作中碰到的問題,希望能相互交流學習。
今天工作碰到一個有趣的問題。thinkphp驗證碼的顯示問題,在這裏小總結一下:
我用的框架是thinkphp3.2,今天魯這個驗證碼,一開始總是顯示一堆圖片編碼,看着像亂碼,咋辦呢?瀏覽器上顯示上圖:
相信有不少人碰到。我是這樣解決的:
1.直接用$this->dispaly();在controller上試過,直接assign過去顯示亂碼,直接用display()過去就成功了。
上圖:
(1)Testconroller上的代碼
<?php
namespace Home\Controller;
class TestController extends CommonController {
public function index() {
$Verify = new \Think\Verify();
$res = $Verify->entry();
// $this->assign('res',$res);
$this->display ('res',$res);
}
}
index.html代碼:
<html>
<head>
</head>
<body>
<h3>歡迎測試,嘻嘻!</h3>
<img alt="" src="{$res}">
</body>
</html>
2.在controller上面不用寫$this->display(),直接在html頁面寫上生成驗證碼方法鏈接就可以了。
Testconroller上的代碼
<?php
namespace Home\Controller;
class TestController extends CommonController {
public function index() {
$Verify = new \Think\Verify();
$res = $Verify->entry();
// $this->assign('res',$res);
// $this->display ('res',$res);
}
}
index.html代碼:
<html>
<head>
</head>
<body>
<h3>歡迎測試,嘻嘻!</h3>
<img alt="" src="__APP__/Test/index">
</body>
</html>
</html>
以上的兩種方法網上也有很多人說,但自己實踐過就特別有意思。新手,大家勿噴……