i know there are many question regarding this problem, but this case is little different ,
i have a main contoller name Hs_controller that run through out the application and i have 2 more controller Frontend_Controller , and Admin_Controller inheriting the 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');
}
}
the app im creating require login on frontend section too, so i import session and form_validation library in the Hs_Controller so i could use them throughout the application,
now the login Action looks like
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 );
}
and the respective view is like
<?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>
the
$this->form_validation->run()is working perfectly, and i can also see the$_POSTform the view and controller but thevalidation_errors()alwasy return empty string ..
what i already tested
parent::__construct();their parent constructor