简体   繁体   中英

Codeigniter get variable (with post value) from another function in one class

Here is my scenario. I have a form with date input that I use as a variable input in my model.

Here is my view for displaying form v_soaotc_daily_index.php

<form class="form_horizontal" method = "post" action="<?php echo site_url('soaotc/getDaily');?>">
     <fieldset> 
         <!-- Date Input name="date_daily" -->
    </fieldset>
    </form>

The form is processed in controller getDaily()

function getDaily(){
        $date_daily = $this->input->post('date_daily');
        $data=array(
            'title'=>'SOA_OTC - Daily',
            'active_otc'=>'active',
            'day'=>$this->model_app->get_Soa_Daily($date_daily)
        );

        $this->load->view('element/v_header',$data);
        $this->load->view('pages/v_soaotc_daily');
        $this->load->view('element/v_footer');
    }

$day will return an array that i will display as a chart using highchart. So i encode json for this array in another function and use POST variable from getDaily()

function daily_json(){
        $this->getDaily(); <!-- connecting to getDaily() -->

        $data=array(
            'day'=>$this->model_app->get_Soa_Daily($date_daily)
        ); 
            .
            .
            .
         blablabla
            .
            .
            .

        echo json_encode($result, JSON_NUMERIC_CHECK);
}

I print_r($day) in view and the result is ok. But the chart can't display because there is no JSON returned from daily_json() . Kindly help me for this. Thank you

As per your description, you should return the JSON value and then print it.

But, you are printing it:

echo json_encode($result, JSON_NUMERIC_CHECK);

Change it to:

return json_encode($result, JSON_NUMERIC_CHECK);

And in view, echo it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM