codeigniter - 一个接一个地从同一个控制器调用两个函数,第二个函数失败

时间:2014-05-27 16:08:35

标签: php codeigniter

这个让我卡住了! 我在控制器中有两个功能,可以从菜单中独立调用,它们工作正常。 我想在月末例程(在同一个控制器中),一个接一个地调用它们;第一个函数正常工作并返回调用函数,第二个函数被调用但失败,因为$ model变量的加载失败。

以下是月末例程的代码,

function month_end_routines()
{
    // create stock inventory valuation report in excel format
    $export_excel                   =   1;
    $this                           ->  inventory_summary($export_excel);

    // create negative stock
    $export_excel                   =   1; 
    $this                           ->  inventory_negative_stock($export_excel);
    echo 'debug 2';

    // reset rolling inventory indicator
    $this                           ->  load->model('Item');
    $this                           ->  load->library('../controllers/items');
    $this                           ->  items->reset_rolling();
}

以下是第一个名为inventory_summary的函数的代码,

function inventory_summary($export_excel=0, $create_PO=0, $set_NM=0, $set_SM=0)
{
    // load appropriate models and libraries
    $this                           ->  load->model('reports/Inventory_summary');
    $this                           ->  load->library('../controllers/items');

    // set variables

    $model                          =   $this->Inventory_summary;
    $tabular_data                   =   array();
    $edit_file                      =   'items/view/';
    $width                          =   $this->items->get_form_width();
    $stock_total                    =   0;

    // get all items
    $report_data                    =   $model->getData(array());

    foreach($report_data as $row)
    {
        $stock_value                =   $row['cost_price'] * $row['quantity'];
        $stock_total                =   $stock_total + $stock_value;

        // set up the item_number to handle blanks
        if ($row['item_number'] == NULL) {$row['item_number'] = $this->lang->line('common_edit');}

        $tabular_data[] = array     (
                                    $row['category'],
                                    anchor  (
                                            $edit_file.$row['item_id'].'/width:'.$width, 
                                            $row['item_number'],
                                            array('class'=>'thickbox','title'=>$this->lang->line('items_update'))
                                            ),
                                    $row['reorder_policy'],
                                    $row['name'], 
                                    $row['cost_price'], 
                                    $row['quantity'], 
                                    $stock_value, 
                                    $stock_total
                                    );
    }

    $today_date                     =   date('d/m/Y; H:i:s', time());

    $data = array   (
                    "title"         =>  $this->lang->line('reports_inventory_summary_report'),
                    "subtitle"      =>  ' - '.$today_date.' '.$this->lang->line('common_for').' '.$this->db->database.'.',
                    "headers"       =>  $model->getDataColumns(),
                    "data"          =>  $tabular_data,
                    "summary_data"  =>  $model->getSummaryData(array()),
                    "export_excel"  =>  $export_excel
                    );

    if ($export_excel == 1)
    {
        $this->load->model('Common_routines');
        $this->Common_routines->create_csv($data);
    }
    else
    {
        $this->load->view("reports/tabular", $data);
    }

    return;

..这里是第二个函数的代码,

function inventory_negative_stock($export_excel=0, $create_PO=0, $set_NM=0, $set_SM=0)
{
    echo 'debug 1.5';
    $this                           ->  load->model('reports/Inventory_negative_stock');
    $this                           ->  load->library('../controllers/items');
    echo 'debug 1.6';

    $model                          =   $this->Inventory_negative_stock;
    var_dump($model);
    $tabular_data                   =   array();
    $edit_file                      =   'items/view/';
    $width                          =   $this->items->get_form_width();
    echo 'debug 1.7';
    $report_data                    =   $model->getData(array());
    echo 'debug 1.8';
    foreach($report_data as $row)
    {

        // set up the item_number to handle blanks
        if ($row['item_number'] == NULL) {$row['item_number'] = $this->lang->line('common_edit');}

        // load each line to the output array
        $tabular_data[] = array(
                                $row['category'],
                                anchor  (
                                        $edit_file.$row['item_id'].'/width:'.$width, 
                                        $row['item_number'],
                                        array('class'=>'thickbox','title'=>$this->lang->line('items_update'))
                                        ),
                                $row['name'],
                                $row['cost_price'], 
                                $row['quantity']
                                );
    }

    // load data array for display
    $today_date                     =   date('d/m/Y; H:i:s', time());
    $data = array   (
                    "title"         => $this->lang->line('reports_negative_stock'),
                    "subtitle"      => ' - '.$today_date.' '.$this->lang->line('common_for').' '.$this->db->database.'.',
                    "headers"       => $model->getDataColumns(),
                    "data"          => $tabular_data,
                    "summary_data"  => $model->getSummaryData(array()),
                    "export_excel"  => $export_excel
                    );

    if ($export_excel == 1)
    {
        $this->load->model('Common_routines');
        $this->Common_routines->create_csv($data);
    }
    else
    {
        $this->load->view("reports/tabular", $data);
    }

    return;
}

这条线路失败了 $模型= $这 - > Inventory_negative_stock;

在第一个函数中,$ model被正确加载。在第二个,它不是。

调用这些函数的顺序无关紧要; $ model总是无法在第二个函数中加载。

任何帮助都会很棒,并提前感谢。我希望我已经提供了足够的代码;如果您需要更多信息,请告诉我。

根据要求,这是Inventory_negative_stock中的代码,

<?php
require_once("report.php");
class Inventory_negative_stock extends Report
{
    function __construct()
    {
        parent::__construct();
    }

    public function getDataColumns()
    {

        return array    (
                        $this->lang->line('reports_category'), 
                        $this->lang->line('reports_item_number'), 
                        $this->lang->line('reports_item_name'), 
                        $this->lang->line('reports_cost_price'), 
                        $this->lang->line('reports_count')
                        );
    }

    public function getData(array $inputs)
    {
        $this->db->select('category, name, cost_price, quantity, reorder_level, reorder_quantity, item_id, item_number');
        $this->db->from('items');
        $this->db->where("quantity < 0 and deleted = 0");
        $this->db->order_by('category, name');

        return $this->db->get()->result_array();
    }

    public function getSummaryData(array $inputs)
    {
        return array();
    }
}
?>

0 个答案:

没有答案