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

时间:2015-01-29 04:49:30

标签: php codeigniter

我有这个分页功能abc,我想把这个功能传递给另一个函数elseif部分,如果部分我想通过视图传递$ 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

        }

在下面的函数中,如果我希望传递abc函数$ data part in view admin ..我怎样才能传递它以便我可以在该视图中进行分页

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(); ?> 

但是出现错误未定义的变量书籍和本书变量是在abc函数中定义的,其数据通过login process elseif部分在视图管理视图中通过$ aaa变量传递请帮我解决一下

1 个答案:

答案 0 :(得分:0)

  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);
        }