views:

186

answers:

4

Ok i have this controller:

class ExampleController extends AppController {

    var $name = 'Example';


    public function test_me () {

      $this->Example->Create();

      $this->Example->set(  'variable_from_db_1' => 'random_value_1',
                            'variable_from_db_2' => 'random_value_2' );


     //here, how can i access to variable_from_db_1 and 2 in $this->Example?
     //???? i've tried $this->data and $this->Example->data but nothing to do

}

}

Do you have some hints for me?

+1  A: 

you can explore the data with: debug( $this->Example );

the data is it's own array: $this->Example->data['variable_from_db_1'];

Adam
+1  A: 

In the related view you can access it like this:

echo $variable_from_db_1.'<br />';
echo $variable_from_db_2.'<br />';

In the controller call

debug($this->data);
powtac
i have to access them in the controller, not in the view
avastreg
debug($this->Example->data); didn't work for me
avastreg
Its: debug($this->data); sorry
powtac
+1  A: 

I don't think you can do that.

You can assign your model data to a $this->data array like this:

$this->data['variable_from_db_1'] = $value; $this->set('variable_from_db_1', $value);

So know you can access $this->data within the controller.

I think if you want to save data to your actual Model, you might have to implement the getter / setter method in your model...

KienPham.com
A: 

I think you cannot do this in controller, normally set calls are moved to the end area of actions and all the operations on the such variables must be performed before 'set'ing it for later access in views.

Mithun P