Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get values from Zend_Db_Table_Row Object array

i am using a zend model which returns me an object in form of $row with all values

but i am not able to get value from this array . is this posible to get values without foreach

this is the array returned

     Zend_Db_Table_Row Object
   (
    [_data:protected] => Array
        (
            [user_id] => 2
            [udid] => 34
            [firstname] => a
            [lastname] => a
            [email] => [email protected]
            [username] => abc
            [password] => c91718531fd9f8b89c4e
            [created_date] => 2010-02-11
            [updated_datetime] => 2012-06-25 12:48:17
            [lastlogin_datetime] => 
            [group_id] => 2
            [status] => Active
        )
 )

i need to get the user_id,firstname,email from this array

any help will be appreciated .

i have tried like

$forgotpassword = $userModel->forgotpassword ( $post ); // which contains this array

$id = $forgotpassword['_data:protected']['id']; exit; // but doesnt seem to work

like image 895
Rinzler Avatar asked Dec 05 '25 20:12

Rinzler


1 Answers

You cannot access _data directly. It's protected.

From the ZF Reference Guide on Naming Conventions:

[…] variables that are declared with the "private" or "protected" modifier, the first character of the variable name must be a single underscore.

You can do either do (due to __get/__set)

echo $forgotpassword->user_id;

or (due to ArrayAccess)

echo $forgotpassword['user_id'];

or (if you want an array)

$array = $forgotpassword->toArray();
echo $array['user_id'];

Please see the Reference Guide and the code

  • http://framework.zend.com/manual/en/zend.db.table.row.html
  • http://framework.zend.com/svn/framework/standard/trunk/library/Zend/Db/Table/Row/Abstract.php
like image 146
Gordon Avatar answered Dec 08 '25 12:12

Gordon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!