문제
어떤 방법이 사용하는 유효성 검사에 로그인 형태에서 간단한 인증에서 리튬을 습니다.내가 알고있는 그것은 더 나은 사용하는 유효성 검사에서 모델이지만,로그인 양식이 없이 모델,그래서,내가 이해하고,필요 사용하는 유효성 검사에서 SessionsController,but I don't know how to do it(
내가 무엇을 하려고에서 SessionsController:
<?php
namespace app\controllers;
use lithium\security\Auth;
use lithium\storage\Session;
use lithium\util\Validator;
class SessionsController extends \lithium\action\Controller {
private $rules = array(
'password' => array(
array('notEmpty', 'message' => 'password is empty'),
),
'email' => array(
array('notEmpty', 'message' => 'email is empty'),
array('email', 'message' => 'email is not valid')
)
);
public function add() {
if ($this->request->data && Auth::check('default', $this->request)) {
return $this->redirect('/');
}
// Handle failed authentication attempts
$errors = Validator::check($this->request->data, $this->rules);
return compact('errors');
}
public function delete() {
Auth::clear('default');
return $this->redirect('/');
}
/* ... */
}
고 난 후 기대 빈 양식을 보냈다 것으로 렌더링된 오류,에서 같은 사용자 생성에서습니다.그러나 오류가 없을 보였다,그냥 로그인 폼을 다시합니다.할 수 있습니지 검증 형태 없는 모델과 작업을 수행할 수 있는 방법을 리튬?
감사합니다.
해결책
는 오류를 렌더링에서 양식은 엔터티를 얻을 수 있다는 것을 의미합니다 형태로 만들면 그것으로 $this->form->create($user)
.이 경우에만,오류 표시에 감사의 형태우 자동으로 합니다.
는 경우에 귀하의 필요에서 확인 컨트롤러 들어오는 데이터를 확인할 수 있습니다 $this->request->data['password']
과 오류를 반환하는 데 필요한 핸들 자신에 의해서 양식 보기(과 if (!empty($errors))
예를 들어)
제휴하지 않습니다 StackOverflow