在尝试创建邮件视图并将变量传递给它时,我遇到了这个错误:
未定义变量:username(查看:/Applications/MAMP/htdocs/laravel/app/views/emails/auth/activate.blade.php)
这是我的Blade View有未定义的var:
Hello {{ $username }},
Please activate your account using the following link
{{ $link }}
这是我的控制器:
<?php
class AccountController extends BaseController {
public function getCreate() {
return View::make('account.create');
}
//Validation
public function postCreate() {
$validator = Validator::make(Input::all(),
array(
'email' => 'required | max:50 | email | unique:users',
'username' => 'required | max:20 | min:3 | unique:users',
'password' => 'required | min:6',
'password_again' => 'required | same:password'
)
);
if($validator->fails()) {
return Redirect::route('account-create')
->withErrors($validator)
->withInput();
} else {
//Create Account
$email = Input::get('email');
$username = Input::get('username');
$password = Input::get('password');
//Activation Code
$code = str_random(60);
$user = User::create (array(
'email'=> $email,
'username'=> $username,
'password'=> Hash::make($password),
'code'=> $code,
'active'=> 0
));
if ($user) {
//Sending email
Mail::send('emails.auth.activate', array('link' => URL::route('account-activate', $code), 'username' => $username), function ($message) use ($user) {
$message->to($user->email, $user->username)->subject('Activate Your Account');
});
return Redirect::route('home')
->with('global', 'Check your inbox for your conformation!');
}
}
}
public function getActivate($code) {
return $code;
}
}
我是Laravel和PHP的新手,我非常感谢你的帮助!
答案 0 :(得分:-2)
我发现了错误!我从我的HomeController调用视图而没有定义那里的变量