tags:

views:

151

answers:

3

Hi guys

I have a problem in calling a function from a function. These are the two functions:

function getevents() {
    $date = $this->input->post('attendanceDateadd'); 
    $Event = $this->input->post('Event'); 
    $Timing = $this->input->post('Timing'); 
    $CompanyName = $this->input->post('CompanyName'); 
    $EventDescription = $this->input->post('EventDescription');

    $res = $this->eventmodel->getevents($date,$Event,$Timing,$CompanyName,$EventDescription);

    if($res == true) {
        $this->session->set_flashdata('response', 'data added successfully !');
    } else {
        $this->session->set_flashdata('response','data already exsists !');
    }
    redirect('EventController/events'); 
}

function Companyname() {   
    $data['Companyname'] = $this->eventmodel->getCompanyname();
    //print_r($data['Companyname']);
    $this->load->view('addevents',$data);
}

I am trying to call the function Company name in previous function. Can anyone guide me?

A: 

Just write Companyname();.

If your code is inside a class then call it like so: $this->Companyname();.

Jan Hančič
Jan i do tried that
udaya
Then tell us more about your problem. What have you tried so far, did you get any errors. Is the code you posted inside of a class or not. Are the functions in the same file/class, if not are both files included, etc.
Jan Hančič
+2  A: 

It seems that your functions are inside a class, so you must call your function like this:

$this->Companyname();
Tatu Ulmanen
A: 

If this function is inside a class, then it should probably be

function Companyname() {   
    $this->data['Companyname'] = $this->eventmodel->getCompanyname();
    //print_r($data['Companyname']);
    $this->load->view('addevents',$this->data);
}

if not, you have to initialize $data before (and $this makes no sense anymore):

function Companyname() {
    $data = array();
    $data['Companyname'] = $this->eventmodel->getCompanyname();
    //print_r($data['Companyname']);
    $this->load->view('addevents',$data);
}

You should provide a more complete code example.

The other thing:

You wrote:

i am tring to call the function Company name in previous function.

  1. Do you mean you try to call the function Companyname that you define in your code, i.e. function Companyname() {}, and have problem with this or
  2. Do you try to call the function/method $this->eventmodel->getCompanyname() inside Companyname and have problems with that.

If the first case applies, I cannot see where you call Companyname in getevents (am I blind??)

Felix Kling
I'm just curious what could possibly posses a framework to not allow you to just use `$this->CompanyName()`
Chacha102