|
发表于 2013-5-21 14:39:14
|
显示全部楼层
本帖最后由 imhuzi 于 2013-5-21 18:37 编辑
加上HMVC后,原来的表单验证用不了了。我吧所有验证规则放在了:config/form_validation.php里,如下:- $config = array(
- 'account/signin/session'=>array(
- array(
- 'field'=>'login_key',
- 'label'=>'邮箱地址',
- 'rules'=>'trim|required|valid_email|xss_clean',
- ),
- array(
- 'field'=>'password',
- 'label'=>'登录密码',
- 'rules'=>'trim|callback_md5password_check|required',
- ),
- ),
- 'app/permission/user/add'=>array(),
- )
复制代码 account是controller,
account的代码如下:- class Account extends CI_Controller {
- //put your code here
- function __construct() {
- parent::__construct();
- $this->load->model('Account_model');
- $this->load->library('form_validation');
- }
- public function index(){
- $this->load->view('account/signin');
- }
- /**
- * 登录
- */
- public function signin($slug = '') {
- if ($slug !== 'session') {
- $this->load->view('account/signin');
- } else {
- //登录表单验证
- $this->load->helper('url');
- $valid_flag = $this->form_validation->run();
- //登录处理
- $signin_flag = false;
- if($valid_flag!=FALSE){
- $signin_flag = $this->Account_model->do_signin();
- }
-
- if (!$valid_flag || !$signin_flag) {
- //设置提示信息并跳转
- $this->session->set_flashdata('validation_error_messages', validation_errors_array());
- setFlash_Message('error', 'Email Account or Password error.');
- redirect('/account/signin');
- } else {
- redirect('/app/');
- }
- }
- }
-
- public function signout(){
- }
- /**
- * 检查md5密码是否正确
- * @param type $str
- * @return boolean
- */
- public function md5password_check() {
- $pass = $this->input->get_md5PasswordValue('password');
- if ($pass == -1 || empty($pass)) {
- $this->form_validation->set_message('md5password_check', '密码不能为空');
- return FALSE;
- } else {
- return TRUE;
- }
- }
- }
复制代码 我跟踪调试后发现:在CI_Form_validation.php里的run方法去不到验证规则,不知道是什么问题,Hex大神...
|
|