[請益] post被連續觸發了兩次

看板PHP作者 (泡麵)時間11年前 (2014/09/06 04:49), 11年前編輯推噓2(209)
留言11則, 5人參與, 最新討論串1/1
各位前輩大家好 小弟最近用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('ql4au04@example.com','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://www.ptt.cc/bbs/PHP/M.1409950193.A.3B8.html

09/06 09:02, , 1F
真猛,用vim編code耶,程式碼裡還夾雜 :wq ...
09/06 09:02, 1F

09/06 09:20, , 2F
樓上真內行
09/06 09:20, 2F
ptt 的界面vim太像 不小心就用了... 用vim也沒比較強 還不是一直有問題XD 目前解決了 感覺是我命名的方式有問題 把 public function forget 改成 public function remind 就不會同時被觸發兩次了 這是我目前的猜測和解決辦法 不知道是不是還有潛藏其他問題 ※ 編輯: ql4au04 (223.142.34.31), 09/06/2014 14:38:56

09/07 00:12, , 3F
同名 function 被當 constructor ?
09/07 00:12, 3F

09/07 00:42, , 4F
對XD 感謝指出問題!
09/07 00:42, 4F

09/07 01:33, , 5F
可是php不是早就改成用__construct()了嗎
09/07 01:33, 5F

09/07 01:34, , 6F
你Laravel至少要php5.4 不會再把同名函式當ctor了
09/07 01:34, 6F
我php的版本是5.5.3 測試的結果是 如果有construct 則同名函式不會有問題 可是如果沒有 同名函式一樣會被視為construct誒 ※ 編輯: ql4au04 (223.142.114.155), 09/08/2014 03:22:20

09/08 16:42, , 7F
妙哉 以前改過一個別人的plugin就是用同名函式當ctor
09/08 16:42, 7F

09/08 16:42, , 8F
幫他改成 __construct 才能正常執行 o_O
09/08 16:42, 8F

09/08 20:23, , 9F
沒__construct也沒繼承時會用同名method當constructor
09/08 20:23, 9F


09/17 22:49, , 11F
感謝ken大補充!!
09/17 22:49, 11F
文章代碼(AID): #1K2Y7nEu (PHP)
文章代碼(AID): #1K2Y7nEu (PHP)