我知道有很多关于这个问题的问题,但这种情况没什么不同,
我有一个主要的控制器名称Hs_controller
贯穿整个应用程序,我还有2个控制器Frontend_Controller
,Admin_Controller
继承了Hs_Controller
class Hs_Controller extends CI_Controller {
public $data = array();
function __construct() {
parent::__construct();
$this->data["errors"] = array();
$this->data["site_name"] = config_item("site_name");
$this->data["meta_title"] = config_item("site_name");
$this->load->helper("form");
$this->load->library("session");
$this->load->library('form_validation');
}
}
我正在创建的应用程序也需要在前端部分登录,所以我在Hs_Controller
中导入会话和form_validation库,所以我可以在整个应用程序中使用它们,
现在登录操作看起来像
public function login() {
$validation_rules = $this->user_r->rules;
$this->form_validation->set_rules( $validation_rules );
echo " form controllers : <br/>";
echo " validation :";
var_dump($this->form_validation->run());
echo "<br/>";
echo " errors :";
var_dump(validation_errors());
echo "<br/>";
echo " post :";
var_dump($_POST);
echo "<hr/>";
if ( $this->form_validation->run() == TRUE ) {
// we can login the user
}
$this->data["subview"] = "user/login";
$this->load->view("_layout_modal" , $this->data );
}
,各自的观点就像
<?php
echo " form view : <br/>";
// echo " validation :";
// var_dump($this->form_validation->run());
// echo "<br/>";
echo " errors :";
var_dump(validation_errors());
echo "<br/>";
echo " post :";
var_dump($_POST);
echo "<hr/>";
?><div class="model-header">
<h3>Login</h3>
<p> hi user</p>
</div>
<div class="model-body"><?php
echo validation_errors();
echo form_open();
?><ul><?php
?><li><label>email</label><?php echo form_input("email"); ?></li><?php
?><li><label>password</label><?php echo form_password("password"); ?></li><?php
?><li><?php echo form_submit("submit" , "log in" , 'class="btn "'); ?></li><?php
?></ul><?php
echo form_close();
?></div>
$this->form_validation->run()
工作正常,我也可以看到$_POST
构成视图和控制器,但validation_errors()
alwasy返回空字符串..
我已经测试过的内容