• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
access helper function inside controller

#1
[eluser]ranjitbd[/eluser]
Code:
// this is the controller method from where i called a function from helper file
function service_provider_add_do()
    {
        global $data;
        $data['name'] = $this->input->post('name', TRUE);
        $data['service_type'] = $this->input->post('service_type', TRUE);
        $data['contact_person'] = $this->input->post('contact_person', TRUE);
        $data['address'] = $this->input->post('address', TRUE);
        $data['city'] = $this->input->post('city', TRUE);
        $data['zip_code'] = $this->input->post('zip_code', TRUE);
        $data['state'] = $this->input->post('state', TRUE);
        $data['country'] = $this->input->post('country', TRUE);

        $data['date_time'] = date('Y-m-d H:i:s');
        $data['session_id'] = $this->session->userdata('session');
        
        $result = $this->admin_model->service_provider_add_do($data);
        flag_message($result, 'admin/admin/service_provider_add');
    }



// if i write flag_message() method inside the controller it works fine..
//this is the function inside my helper file

function flag_message($result, $page = NULL)
    {    
        if($page)
        {
            $saved = 'Data Save Successfully';
            $fails = 'Data Failed';
            if($result)
            {
                $menu_data = array
                    (
                      'message' => $saved,
                      'add' => TRUE
                     );
                $this->session->set_userdata($menu_data); // this is line 103
// showing Parse error is the above line......................................
                redirect($page);
            }
            else
            {
               $menu_data = array
                    (
                        'message' => $fail,
                        'add' => FALSE
                    );
               $this->session->set_userdata($menu_data);
               redirect($page);
            }
        }
        redirect('admin/admin/logout');
    }

// Parse error: parse error in C:\xampp\htdocs\travelmartbd\system\helpers\common_function_helper.php on line 103
// what is wrong here...

#2
[eluser]ranjitbd[/eluser]
[quote author="ranjitbd" date="1260807351"][code]
// when i put the same method inside my customized library
// it shows the following error in that same line number 103
// that line:
$this->session->set_userdata($menu_data);

Fatal error: Call to a member function set_userdata() on a non-object in C:\xampp\htdocs\travelmartbd\appl

#3
[eluser]rogierb[/eluser]
$this-> (the CI superobject)does not exists in a helper or in a library.

Read the user guide and you will understand why.
A tip: you have to use get_instance()


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.