作者ql4au04 (泡麵)
看板PHP
標題[請益] post被連續觸發了兩次
時間Sat Sep 6 04:49:47 2014
各位前輩大家好
小弟最近用laravel做寄發認證信的時候
發現同一個post會同時被觸發兩次
所以導致使用者會一次收到兩封認證信
以前寫都覺得沒關係 只要有寄出就好
可是現在覺得這樣很容易造成問題
所以來請教各位前輩 該如何解決
--------以下為簡略程式碼-----------
controller :
class Forget extends BaseController{
public function forget(){
$input = Input::all();
$user = User::where('account',$input['account'])->get()->first();
if($user->count()){
//產生token 存進database
Mail::send('reminder',array('url'=>'www.example.com','name'=>$user->name),
function($message) use ($user){
$message->from('
[email protected]','ql4au04');
$message->to($user->email,$user->name)->subject('reminder');
});
return Redirect::to('/');
}else{
return Redirect::to('/')->withErrors();
}
}
}
router:
Route::get('/','User@index');
Route::post('/forget',array('as'=>'forget','uses'=>'forget@forget'));
--
Sent from my CASIO fx-991es .
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 223.142.3.25
※ 文章網址: http://webptt.com/m.aspx?n=bbs/PHP/M.1409950193.A.3B8.html
1F:推 shadowjohn: 真猛,用vim編code耶,程式碼裡還夾雜 :wq ... 09/06 09:02
2F:→ MOONRAKER: 樓上真內行 09/06 09:20
ptt 的界面vim太像 不小心就用了...
用vim也沒比較強 還不是一直有問題XD
目前解決了 感覺是我命名的方式有問題
把 public function forget 改成 public function remind
就不會同時被觸發兩次了 這是我目前的猜測和解決辦法
不知道是不是還有潛藏其他問題
※ 編輯: ql4au04 (223.142.34.31), 09/06/2014 14:38:56
3F:→ chrisQQ: 同名 function 被當 constructor ? 09/07 00:12
4F:→ ql4au04: 對XD 感謝指出問題! 09/07 00:42
5F:→ MOONRAKER: 可是php不是早就改成用__construct()了嗎 09/07 01:33
6F:→ MOONRAKER: 你Laravel至少要php5.4 不會再把同名函式當ctor了 09/07 01:34
我php的版本是5.5.3 測試的結果是 如果有construct 則同名函式不會有問題
可是如果沒有 同名函式一樣會被視為construct誒
※ 編輯: ql4au04 (223.142.114.155), 09/08/2014 03:22:20
7F:→ MOONRAKER: 妙哉 以前改過一個別人的plugin就是用同名函式當ctor 09/08 16:42
8F:→ MOONRAKER: 幫他改成 __construct 才能正常執行 o_O 09/08 16:42
9F:推 Kenqr: 沒__construct也沒繼承時會用同名method當constructor 09/08 20:23
11F:→ ql4au04: 感謝ken大補充!! 09/17 22:49