如何将一个函数的数据传递给另一个函数,然后在另一个函数的视图中传递该数据


How to pass data of one function to other and then pass that data inside the view of the other function?

我有这个分页函数abc,我想将这个函数传递给另一个函数elseif部分,而在那个else if部分中,我想通过视图传递$data['books']...这是我的控制器,其他功能是我想在其中传递ABC函数的数据

public function abc($offset = 0){
               $this->load->model('insert_model');
             //$data ['query'] = $this->insert_model->view_data(); 
               $this->load->library('table');
            // Load Pagination
               $this->load->library('pagination');
            // Config setup
            $config['base_url'] = base_url().'/welcome/';
        $items= $config['total_rows'] = 20;
            $perpage=$config['per_page'] = 1;
            // I added this extra one to control the number of links to show up at each page.
            $config['num_links'] = 5;
            // Initialize
            $this->pagination->initialize($config);
            // Query the database and get results
            // Here we add the limit and the offset
            // The second parameter is the limit, since we are showing
            // 10 per page, the limit should be 10
            $data['books'] = $this->db->get('register',5, $offset);
            // Create custom headers
            $header = array('id','username','lastname','email' , 'password', 'image','status');
            // Set the headings
            $this->table->set_heading($header);
            // Load the view and send the results
        }

在以下函数的 elseif 部分中,我想将 ABC 函数传递$data视图管理员中的部分。 如何传递它以便我可以在该视图中进行分页

public function login_process()
    {
        $this->load->model('insert_model');
        $data['users'] = array(
                            'fname' => $this->input->post('fname'),
                            'pass'=> $this->input->post('pass'),
                           ); 

        $status= $this->insert_model->login_test($data);
        $st['ss']=$this->insert_model->stat($data); 
        //print "<pre>"; print_r($status); die();
        if($status == true && $st['ss'] [0] ['status'] == 0)
        {
            $ses = array(
                        'username' =>  $this->input->post('fname'),
                        'password' =>  $this->input->post('pass'),
                );
             $this->session->set_userdata($ses);
             $im['pic']=$this->insert_model->image_fetc();
             $this->load->view('header_view',$im);
             $this->load->view('navside_view');
             $this->load->view('user_view');
        }
        elseif($status == true && $st['ss']['0'] ['status'] == 1)
        {
            $ses = array(
                        'username' =>  $this->input->post('fname'),
                        'password' =>  $this->input->post('pass'),
                );
             $this->session->set_userdata($ses);
             $im['pic']=$this->insert_model->image_fetc();
            $this->abc();

             $this->load->view('header_view',$im);
             $this->load->view('navside_view');
             $this->load->view('admin_view', $data);
        }
        else
            {
                $this->load->view('header_view');
             $this->load->view('navside_view');
             $this->load->view('center_view_login');
            }
}

在我的admin_view中,我正在编写以下代码并尝试使用我传递给函数 abc 的管理视图的数据,即$aaa代码是:-

<?php echo $this->table->generate($books); ?>
    <?php echo $this->pagination->create_links(); ?> 

但是出现了错误 未定义的变量 书籍,这个 books 变量是在 abc 函数中定义的,其数据通过登录过程传递 elseif 部分通过变量在视图管理视图中$aaa请帮助我整理它

  you can try this  
    public function abc($offset = 0, $status){
               $this->load->model('insert_model');
             //$data ['query'] = $this->insert_model->view_data(); 
               $this->load->library('table');
            // Load Pagination`enter code here`
               $this->load->library('pagination');
            // Config setup
            $config['base_url'] = base_url().'/welcome/';
        $items= $config['total_rows'] = 20;
            $perpage=$config['per_page'] = 1;
            // I added this extra one to control the number of links to show up at each page.
            $config['num_links'] = 5;
            // Initialize
            $this->pagination->initialize($config);
            // Query the database and get results
            // Here we add the limit and the offset
            // The second parameter is the limit, since we are showing
            // 10 per page, the limit should be 10
            $data['books'] = $this->db->get('register',5, $offset);
            if($status){
            return $data['books'];
            }
            // Create custom headers
            $header = array('id','username','lastname','email' , 'password', 'image','status');
            // Set the headings
            $this->table->set_heading($header);
            // Load the view and send the results
        }
second function elseif part
elseif($status == true && $st['ss']['0'] ['status'] == 1)
        {
            $ses = array(
                        'username' =>  $this->input->post('fname'),
                        'password' =>  $this->input->post('pass'),
                );
             $this->session->set_userdata($ses);
             $im['pic']=$this->insert_model->image_fetc();
             $aaa = $this->abc(0,true);

             $this->load->view('header_view',$im);
             $this->load->view('navside_view');
             $this->load->view('admin_view', $aaa);
        }