【发布时间】:2014-11-13 18:36:51
【问题描述】:
我正在尝试发送包含变量的发布请求,但它说该变量未定义,这是我的代码.. 第一个函数是包含表单的视图。 第二个函数是表单的post请求的回调。 我在视图中回显了变量,它成功了,但错误出现在第二个函数中..
public function reset($code)
{
return View::make('recover', array('code' => $code, 'passwordReset' => 1,'noLoginForm' => 1));
}
public function postResetPassword()
{
$validator = Validator::make(Input::all(), array('temppassword' => 'required','newpassword' => 'required|min:6','cnewpassword' =>'required|same:newpassword'));
if($validator->fails())
return View::make('recover', array('passwordReset' => 1,'noLoginForm' => 1))->withErrors($validator);
else {
// The error shows up in the following line in the code variable comparison
$user = User::where('temp_password','!=','')->where('code','=',$code)->first();
if($user) {
$user->password = Hash::make(Input::get('newpassword'));
$user->temp_password = '';
if($user->save())
return Redirect::route('login')->with('msg','Password changed correctly, use your new password to login.');
} else {
return View::make('recover', array('passwordReset' => 1,'noLoginForm' => 1,'error' =>'Invalid temporary password, please make sure you typed the password sent to you correctly.'));
}
}
}
这是错误日志
[2014-11-13 09:50:15] production.ERROR: exception 'ErrorException' with message 'Undefined variable: code' in C:\wamp\www\buddyly\app\controllers\UserController.php:155
Stack trace:
#0 C:\wamp\www\buddyly\app\controllers\UserController.php(155): Illuminate\Exception\Handler->handleError(8, 'Undefined varia...', 'C:\wamp\www\bud...', 155, Array)
#1 [internal function]: UserController->postResetPassword()
#2 C:\wamp\www\buddyly\vendor\laravel\framework\src\Illuminate\Routing\Controller.php(231): call_user_func_array(Array, Array)
#3 C:\wamp\www\buddyly\bootstrap\compiled.php(5776): Illuminate\Routing\Controller->callAction('postResetPasswo...', Array)
#4 C:\wamp\www\buddyly\bootstrap\compiled.php(5764): Illuminate\Routing\ControllerDispatcher->call(Object(UserController), Object(Illuminate\Routing\Route), 'postResetPasswo...')
#5 C:\wamp\www\buddyly\bootstrap\compiled.php(4971): Illuminate\Routing\ControllerDispatcher->dispatch(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request), 'UserController', 'postResetPasswo...')
#6 [internal function]: Illuminate\Routing\Router->Illuminate\Routing\{closure}()
#7 C:\wamp\www\buddyly\bootstrap\compiled.php(5329): call_user_func_array(Object(Closure), Array)
#8 C:\wamp\www\buddyly\bootstrap\compiled.php(4996): Illuminate\Routing\Route->run(Object(Illuminate\Http\Request))
#9 C:\wamp\www\buddyly\bootstrap\compiled.php(4984): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request))
#10 C:\wamp\www\buddyly\bootstrap\compiled.php(715): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request))
#11 C:\wamp\www\buddyly\bootstrap\compiled.php(696): Illuminate\Foundation\Application->dispatch(Object(Illuminate\Http\Request))
#12 C:\wamp\www\buddyly\bootstrap\compiled.php(7744): Illuminate\Foundation\Application->handle(Object(Illuminate\Http\Request), 1, true)
#13 C:\wamp\www\buddyly\bootstrap\compiled.php(8351): Illuminate\Session\Middleware->handle(Object(Illuminate\Http\Request), 1, true)
#14 C:\wamp\www\buddyly\bootstrap\compiled.php(8298): Illuminate\Cookie\Queue->handle(Object(Illuminate\Http\Request), 1, true)
#15 C:\wamp\www\buddyly\bootstrap\compiled.php(10957): Illuminate\Cookie\Guard->handle(Object(Illuminate\Http\Request), 1, true)
#16 C:\wamp\www\buddyly\bootstrap\compiled.php(657): Stack\StackedHttpKernel->handle(Object(Illuminate\Http\Request))
#17 C:\wamp\www\buddyly\public\index.php(49): Illuminate\Foundation\Application->run()
#18 C:\wamp\www\buddyly\server.php(19): require_once('C:\wamp\www\bud...')
#19 {main} [] []
【问题讨论】:
-
您的
$code已被调用但尚未在您的方法中设置,或者您如果$code来自输入,则需要Input::get('code')
标签: php variables laravel undefined