我一直在关注 Envato 在 Tutplus 上的本教程:https ://tutsplus.com/course/build-a-cms-in-codeigniter/ 。我正在验证登录表单的部分。我的问题是我不能在登录系统中使用我的表单验证规则。我的代码如下:
user_m.php
<?php
class User_M extends MY_Model {
public $rules = array( // I can't use this rules in my controller
'email' => array( // for email
'field' => 'email',
'label' => 'Email',
'rule' => 'trim|required|valid_email|xss_clean'
),
'password' => array( // for password
'field' => 'password',
'label' => 'Password',
'rule' => 'trim|required'
)
);
}
用户.php
<?php
class User extends Admin_Controller {
public function __construct()
{
parent::__construct();
}
public function login()
{
// Set form
$rules = $this->user_m->rules; // get the value from user_m model and it works well
// this is not works. this is my problem
$this->form_validation->set_rules($rules);
// if we use this comment code then it works
//$this->form_validation->set_rules('email', 'Email', 'rim|required|valid_email|xss_clean');
// $this->form_validation->set_rules('password', 'Password', 'required');
// Process form
if ( $this->form_validation->run() == TRUE ) { // show the error msg if form problem occurs
// We can login and redirect
}
}