In yii, I pull the data out of the database as follows:


If done:

 echo '<pre>';print_r($record);echo '</pre>'; 

That displays:

 [_attributes:CActiveRecord:private] => Array ( [id] => 1 [login] => Myname [passwd] => 123456 [created] => 0000-00-00 00:00:00 ) 

How to use this array? (I need an id to assign to $a ).

PS As I tried it better not to show you :)

    2 answers 2

    $ record for you is an object and you simply refer to its properties:

     $a = $record->id; echo $a; 
    • tried it did not work, gives an error - bemulima
    • worked))) And so I tried: echo $ record-> id; so no canal yes? - bemulima
    • Why? Should too. - Zhukov Roman
    • Actually, neither should be. Or I misunderstand OOP in PHP ... All private members are available only in the class. Therefore, you cannot simply take and get the value. To get you need to write a method GetId (), and for assigning SetId (). Or make members of the public class. At least in C ++. - Ray

    So the members are closed, right? Write a method SetId($_id) and pass your $a