Magento 1.9 Model – How to Get Certain Element Value from Array-Object

arraymagento-1.9modelobject

below you can see the value genrate through print_r
when i am trying get value of

$post->PostContent() – return value is "post 1111111111111111Read More"
but i want to get second value that is – "post 1111111111111111post 1111111111111111post 1111111111111111post 1111111111111111post 1111111111111111post 1111111111111111post 1111111111111111post 1111111111111111post 1111111111111111post 1111111111111111post 1111111111111111post 1111111111111111post 1111111111111111post 1111111111111111post 1111111111111111post 1111111111111111post 1111111111111111post 1111111111111111post 1111111111111111post 1111111111111111post 1111111111111111"

<?php foreach ($posts as $post): 
    print_r($post);
    //below you can see the value genrate through print_r
    $post->PostContent();//second value that is long in length and have not included read more
?>

AW_Blog_Model_Blog Object
(
    [_eventPrefix:protected] => core_abstract
    [_eventObject:protected] => object
    [_resourceName:protected] => blog/blog
    [_resource:protected] => 
    [_resourceCollectionName:protected] => blog/blog_collection
    [_cacheTag:protected] => 
    [_dataSaveAllowed:protected] => 1
    [_isObjectNew:protected] => 
    [_data:protected] => Array
        (
            [post_id] => 1
            [title] => post 1 
            [post_content] => post 1111111111111111Read More
            [status] => 1
            [created_time] => יום רביעי, 28 בדצמבר 2016 10:14:59 America/Los_Angeles
            [update_time] => יום רביעי, 28 בדצמבר 2016 15:42:00 America/Los_Angeles
            [identifier] => post1
            [user] => pooja chaurasia
            [update_user] => pooja chaurasia
            [meta_keywords] => 
            [meta_description] => 
            [comments] => 0
            [tags] => 
            [short_content] => post 1111111111111111
            [featured_image] => lady_image.jpg
            [comment_count] => 
            [address] => https://starksdiamonds.com/news/post1/
            [cats] => Array
                (
                    [0] => Array
                        (
                            [title] => News
                            [url] => https://starksdiamonds.com/news/cat/news/
                        )

                )

        )

    [_hasDataChanges:protected] => 1
    [_origData:protected] => Array
        (
            [post_id] => 1
            [title] => post 1 
            [post_content] => post 1111111111111111post 1111111111111111post 1111111111111111post 1111111111111111post 1111111111111111post 1111111111111111post 1111111111111111post 1111111111111111post 1111111111111111post 1111111111111111post 1111111111111111post 1111111111111111post 1111111111111111post 1111111111111111post 1111111111111111post 1111111111111111post 1111111111111111post 1111111111111111post 1111111111111111post 1111111111111111post 1111111111111111
            [status] => 1
            [created_time] => 2016-12-28 18:14:59
            [update_time] => 2016-12-28 23:42:00
            [identifier] => post1
            [user] => pooja chaurasia
            [update_user] => pooja chaurasia
            [meta_keywords] => 
            [meta_description] => 
            [comments] => 0
            [tags] => 
            [short_content] => post 1111111111111111
            [featured_image] => lady_image.jpg
            [comment_count] => 
        )

    [_idFieldName:protected] => post_id
    [_isDeleted:protected] => 
    [_oldFieldsMap:protected] => Array
        (
        )

    [_syncFieldsMap:protected] => Array
        (
        )

)

Best Answer

All Magento Models inherit from the Varien_Object class. This class is part of the Magento system library and not part of any Magento core module. You can find this object at

lib/Varien/Object.php

Magento Models store their data in a protected _data property. The Varien_Object class gives us several methods we can use to extract this data. You will see getData, which will return an array of key/value pairs. This method can also be passed a string key to get a specific field.

$post->getData();
$post->getData('post_content');

There's also a getOrigData method, which will return the Model data as it was when the object was initially populated, (working with the protected _origData method).

$post->getOrigData();
$post->getOrigData('post_content');
Related Topic