Hash
Hash

Reputation: 8030

Codeigniter sending 2 values to the view from controller

Im trying to send 2 values to the view to be used from the controller.

$data1= $this->datalib->is_data();
$data2['name']=$this->namelib->getName();

Im looking to send data1 and data2 so i can use both in two places. What changes i need?

 $this->load->view('person_view', array('value'=> $data1));

thanks.

Upvotes: 0

Views: 124

Answers (7)

Hash
Hash

Reputation: 8030

figured it out. this was the change i needed, ty @Rupam was looking for something like that.

$this->load->view('person_view', array('value'=> $data1,'name'=>$data2['name']));

Upvotes: 0

soedjarwoAli
soedjarwoAli

Reputation: 31

use this one

$dataToShow['data'] = $this->datalib->is_data();
$dataToShow['name'] = $this->namelib->getName();

then to load view

 $this->load->view('person_view', $dataToShow);

so you can access your data on your view with using this variable

 $data and $name

hope will help cheers

Upvotes: 0

Rupam
Rupam

Reputation: 1642

This will do the job

$this->load->view('person_view', array('data1'=> $data1,'data2'=>$data2));

Upvotes: 1

Sreelal P Mohan
Sreelal P Mohan

Reputation: 313

Change the code to

$data['data1']= $this->datalib->is_data();
$data['name']=$this->namelib->getName();

Then pass $data to the view

$this->load->view('person_view', $data);

In the view, use $data1 and $name to access these values.

Upvotes: 0

Dung Tran
Dung Tran

Reputation: 118

You might want to do something like this

$data['temp']= $this->datalib->is_data();
$data['name']=$this->namelib->getName();

Then pass data to view

 $this->load->view('person_view', $data);

In view you can use that two variables as $temp and $name.

echo $temp;
echo $name;

Upvotes: 0

Vinod VT
Vinod VT

Reputation: 7159

try this,

$data['info1']= $this->datalib->is_data();
$data['info2']=$this->namelib->getName();

Pass array $data to view,

$this->load->view('person_view',$data);

In your view person_view.php you can get the values of info1 and info2. Like,

print_r($info1);
print_r($info2);

Upvotes: 1

Craig
Craig

Reputation: 1823

You just add $data1 to the $data array, like this;

$data['name'] = $this->namelib->getName();
$data['is_data'] = $this->datalib->is_data();

Then, pass the $data array to the view;

$this->load->view('person_view', $data);

You will be able to access the data array from the view, like this;

print_r($name);
print_r($is_data);

Hope this helps.

Upvotes: 1

Related Questions