Is it possible to use multiple $ this inside a helper in codeigniter

I am creating a form error logger, but since my register.php controller is filling up I thought to move this to the helper, but the problem is I cannot use $ this.

Yes, I have checked and there are some anders who fix this issue using:

function test()
{
    $CI =& get_instance();
    $CI->load->database();
    echo $CI->db->hostname; // give the config name here (hostname).
}

      

(Quoted from the database Acess config variables from the helper )

However, my problem is that I can only use one model for each function and see how my code that I am trying to move is like this:

function submitCheck() {
    $this->load->model("User");
    if(empty($post)) { //If anything is empty the view will be loaded
        $this->load->view('includes/header.php');
        $this->load->view('error_message.php'); 
        $this->load->view('includes/footer.php'); 

        if(empty($post['firstname'])) //This is for the error log
        {  
            $this->load->helper('array', 'error'); //Loading the helper
            echo $msg = errorLog('firstname');
            $this->load->view('error_message.php');
        }        

        if(empty($post['mail'])) //This is for the error log
        {
            $this->load->helper('error'); //Loading the helper
            echo $msg = errorLog('mail');
        }
    }
    else
    {
        echo "Everything is filled in";
    }
}

      

So, if after the example code I need to do about 4/5 functions for each $ this. Should I create a loader that in terms of loading other loaders, or can I use user_loader to load other views / models.

I'm starting with codeIgniter, so maybe I just thought it was too hard and there is an easy fix, but I can't find it. Any help is determined

Thanks in advance!

+3


source to share


1 answer


According to CodeIgniter documentation :

Unlike most other systems in CodeIgniter, helpers are not written in an object-oriented format. These are simple, procedural functions. each helper function performs one specific task that is independent of other functions.



It is not recommended to use helpers in your case. Better to define your custom library to manage most of your code.

+1


source







All Articles