0

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 $_POST form the view and controller but the validation_errors() alwasy return empty string ..

what i already tested

  1. validation rules are working perfectly,

  2. .htaccess solution on this link also didn't work

  3. $_POST is not empty, i can be access from the controller and view as describe in this link

    1. $this->form_validation->run() is also validation and working
2
  • Just to clarify to ask a question as it's not cleary stated in your question, your Frontend and Admin controllers are extending your Hs Controller? If that is a yes, then each of those are calling the Hs Controllers parent constructor? Commented Oct 9, 2016 at 12:40
  • yes, they are inheriting and they are calling parent::__construct(); their parent constructor Commented Oct 10, 2016 at 7:04

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.