3

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

3
  • 1
    Should be $forgotpassword->_data['id'] Commented Jun 26, 2012 at 7:10
  • @lake Specified column "_data" is not in the row it gives this error Commented Jun 26, 2012 at 7:14
  • 1
    ,ye,variable/method which with protected modifier in class could not be accessed like that,it only can be accessed with $this in class(or it's derived class)'s method,Gordon made a wonderful answer,:=). Commented Jun 26, 2012 at 7:29

1 Answer 1

7

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

Sign up to request clarification or add additional context in comments.

2 Comments

i just want the values of indivual items like id firstname and email from the array . thanks for the answer i will check and tell :)
thank you i got it like you said $id = $forgotpassword->user_id; $email = $forgotpassword->email; $firstname = $forgotpassword->firstname;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.