Welcome Guest, Not a member yet? Register   Sign In
php basics query on data passed to model
#1

[eluser]deepakaggarwal[/eluser]
In my controller, I've:

Code:
...
$data['result'] = $this->db->get('car',array('id'=>$id))->row();
$this->load->view('edit_car',$data);

In my view, I access result as:
Code:
$result->car_color;

All good!

But I'm curious to know 2 things (I'm new to PHP altogether... Hence the curiosity) Smile

1. How does a variable added as an array ($result) gets accessible in view in an object oriented way? Just want to get hint on how this happens in PHP.

2. if I do a var_dump($this) on my view, I do see my passed data as:
Code:
["_ci_cached_vars":protected]=> array(1) { ["result"]=> object(stdClass)#17 (2) { ["car_color"]=> string(5) "green" ["car-make"]=> string(4) "1990" } }
However, I couldn't figure out a way to access result using $this. For example I tried:
$this->result->car_color
$this->result['car_color]
and many more. I want to know when result is within $this, then how to access result using $this-> notation.

thanks.


#2

[eluser]deepakaggarwal[/eluser]
**MISTAKENLY ADDED IN NO CODE FORUM SECTION**

Moderator, please shift my query to appropriate section!
thanks
#3

[eluser]Aken[/eluser]
The $data array passed in $this->load->view() goes through extract(), to create variables based on the array keys. In the view, you would use $result, not using $this.




Theme © iAndrew 2016 - Forum software by © MyBB