0

I need to pass both $data and $object when loading view_nav

 public function home(){
        $this->load->model('get_company_model');
        $this->load->model('bank_account_model');
        $data['results'] = $this->get_company_model->get_All();
        $object['site2']=$this; 
        $this->load->view('view_header');
        $this->load->view('view_nav');
        $this->load->view('view_content');
        $this->load->view('view_footer');
    }

here I need to pass $data[results] and object of the current controller, how can I do this

2 Answers 2

3

You can't pass two variables, but you can combine them into one in hundreds of ways. For example:

$data['site2'] = $object['site2']; // available as $site2 in the view

or

$data['object'] = $object; // available as $object['site2'] in the view

etc...

And then just add $data to the view:

$this->load->view('view_nav', $data);
Sign up to request clarification or add additional context in comments.

2 Comments

here I need to pass $data[results] and object of the current controller, how can I do this
You can pass whatever you want into an array and then pass that array to the view. In this case, you'll have $data['results'] and $data['controller_object'] (assign the actual object to it), and just pass it to the view, like my answer says.
0

If developer wants to get all categories from database into a variable of controller and wants to transfer this resultant array to the associate view, then he/she can follows the following process as well:-

$data = array();
$this->load->model('dbmodel');
$data['item'] = $this->dbmodel->getData('*','catagory',array());
$this->load->view('listing_view', $data);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.