对象的PHP数据访问 [英] PHP access data of an object

查看:127
本文介绍了对象的PHP数据访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个目标,我希望得到一块从,对象是这样的,

I have an object of which I am looking to get a piece of data from, the object looks like this,

    Product Object
(
    [name] => Simon Test Cup
    [code] => 123456789
    [category_id] => 3
    [range_id] => 26
    [price] => 10.00
    [price_logo_add] => 0.25
    [image_id] => 846
    [rank] => 
    [special_offer] => N
    [cartProps] => Array
        (
        )

    [section] => 
    [vatPercentage] => 17.5
    [id] => 551
    [date_created] => 2010-05-25 12:46:57
    [last_updated] => 2010-05-25 14:10:48
    [user_id_updated] => 0
    [_aliases] => Array
        (
            [id] => 551
            [date_created] => 2010-05-25 12:46:57
            [date_updated] => 2010-05-25 14:10:48
            [user_id_updated] => 0
            [name] => Simon Test Cup
            [code] => 123456789
            [category_id] => 3
            [range_id] => 26
            [price] => 10.00
            [price_logo_add] => 0.25
            [image_id] => 846
            [range_image_id] => 848
            [main_image_id] => 847
            [rank] => 
            [special_offer] => N
        )

    [_default] => Array
        (
            [special_offer] => N
        )

    [_related] => Array
        (
            [_related] => Array
                (
                    [range] => stdClass Object
                        (
                            [key] => range
                            [group] => _related
                            [foreignKey] => range_id
                            [indexName] => id
                            [tableName] => cc_range
                            [objectName] => Range
                            [userFieldlyColName] => name
                            [criteria] => id='{%range_id%}'
                            [sqlPostfix] => 
                            [populateOnLoad] => 
                            [objects] => Array
                                (
                                    [26] => Range Object
                                        (
                                            [name] => Shot glasses
                                            [url_name] => shot-glasses
                                            [description] => Personalized shot glasses make great commemorative gifts, souvenirs and wedding favours. Just select your favourite shape and send us a customization form with your logo. See our glassware sale page for info on free logo origination.
                                            [leader] => Customized shot glasses make great commemorative gifts, promotional items and wedding favours.  Individual gift boxes are available so you can give the glasses away easily.
                                            [category_id] => 3
                                            [site_id_csv] => 
                                            [image_id_main] => 565
                                            [image_id_thumb] => 566
                                            [rank] => 
                                            [site] => main
                                            [id] => 26
                                            [date_created] => 2008-05-18 21:39:52
                                            [last_updated] => 2009-02-03 13:49:10
                                            [user_id_updated] => 0
                                            [_aliases] => Array

我想获得从ID的 [范围] = stdClass的对象

推荐答案

正如你可能会看到,你的产品对象有一个属性 range_id

As you might see, your Product object has an attribute range_id:

Product Object
(
    [name] => Simon Test Cup
    [code] => 123456789
    [category_id] => 3
    [range_id] => 26          // <--- here!
    [price] => 10.00
    ...

所以,你应该能够通过拿到ID:

So you should be able to get the ID via:

$object->range_id


但也许,在产品范围类定义,使您能够访问这些信息的方法,你应该使用他们,而不是。你只需要阅读文档如何使用它们。


But probably, the Product and Range classes define methods that allow you to access those information and you should use them instead. You just have to read the documentation how to use them.

这篇关于对象的PHP数据访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆