1
yakczh OP $rules= array(
'username' => 'required', 'password' => 'required|min:8', 'email' => 'required|email|unique:users' ); 比如表单是email, 数据库青字段可能是 users_mail 这种的, 提交的时候提示 SQLSTATE[42S22]: Column not found: 1054 Unknown column 'email' in 'where clause' (SQL: select count(*) as aggregate from `users` where `email` = [email protected]) |
2
ooh 2014-04-08 22:55:12 +08:00
不开debug会有这样的提示?
|
3
huafang 2014-04-08 23:11:34 +08:00 via Android
可以不一致,在控制器里
|
4
yakczh OP @huafang 怎么写
比如 表单是 f1 => users_login f2 =>users_pass f3 =>users_mail $rules= array( 'f1' => 'required', 'f2' => 'required|min:8', 'f3' => 'required|email|unique:users' ); 这里怎么配置? |
5
huafang 2014-04-09 00:16:52 +08:00 via Android
是input获取上进行控制
|
6
yangqi 2014-04-09 00:37:36 +08:00
$user = array(
'user_email' => Input::get('email'), 'user_password' => Input::get('password'), ); $rule = array( 'User_password' => 'required|min:8', 'user_email' => 'required|email|unique:users' ); |
7
imzoke 2014-04-09 07:21:17 +08:00 via Android
仔细看了下,你这是在做唯一性验证时出错吧,unique第一个参数是表名,第二个参数就是字段名,用“,”号分隔。你只需要在验证规则里指定自定义字段名就行了。
至于字段映射,官方文档里是没有的,而且操作方式的不同,应该是没有这个功能。 |
8
yakczh OP 没有映射,耦合性就太强了,要么在表单域的名字全部与数据库表字段一致,要么在controll/route里面挨个赋值 $data = array(
'user_login' => Input::get('f1'), 'user_password' => Input::get('f3'), 'user_email' => Input::get('f2'), ); 然后按表字段来验证 $rules= array( 'user_login' => 'required', 'user_password' => 'required|min:8', 'user_email' => 'required|email|unique:users' ); $validator = Validator::make($data, $rules); 但这样验证出错信息里是表字段为键 Array ( [*messages] => Array ( [user_login] => Array ( [0] => The user login field is required. ) [user_password] => Array ( [0] => The user password field is required. ) [user_email] => Array ( [0] => The user email field is required. ) ) [*format] => :message ) 前台在显示错误提示的时候 只显示The following errors have occurred: 但不会显示具体那个字段出错了,因为找不到对应的键,除非用 {{ $errors->first('user_login', '<li>:message</li>') }} {{ $errors->first('user_password', '<li>:message</li>') }} {{ $errors->first('user_email', '<li>:message</li>') }} 再把数据库表名全部列上去,这样就跟第一种方式一样了 |
9
yakczh OP 这种技术应该叫数据库表页面透明化
|
10
icyflash 2014-04-09 12:13:15 +08:00
MVVM么
|
11
yakczh OP 数据库表字段是 user_email user_pass ... 这种 登录里
$user=array('user_email' => '[email protected]', 'user_pass' => 'xxoo'); if (Auth::attempt($user)){ 这里打印Sql是 select * from `users` where `user_email` = ? and `user_pass` = ? limit 1 页面提示 ErrorException Undefined index: password 换成 $user=array('user_email' => '[email protected]', 'password' => 'xxoo'); if (Auth::attempt($user)){ 这时页面不报错了,但是打印的Sql里没有password条件了,只有 select * from `users` where `user_email` = ? limit 1 提示 {"login_status":"invalid"} |