PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, March 19, 2022

[FIXED] how to make an array of objects that is not from a model into a ArrayDataProvider in Yii 1.1.14?

 March 19, 2022     yii     No comments   

Issue

so my variable contains an array of objects. each object is like this

Array
(
    [0] => CustomAudienceBean Object
        (
            [limit:protected] => 
            [account_id:protected] => 2342354235235
            [approximate_account:protected] => 
            [data_source:protected] => stdClass Object
                (
                    [type] => SEED_BASED
                    [sub_type] => ENGAGEMENT_EVENT_USERS
                    [creation_params] => []
                )

            [type:protected] => 
            [sub_type:protected] => 
            [creation_params:protected] => Array
                (
                )

            [delivery_status:protected] => stdClass Object
                (
                    [code] => 300
                    [description] => Audiences must include at least 20 people to be used for ads.
                )

            [code:protected] => 
            [description:protected] => 
            [external_event_source:protected] => 
            [id:protected] => 23423asdf23423tadf23
            [is_value_based:protected] => 
            [lookalike_audience_ids:protected] => 
            [lookalike_spec:protected] => stdClass Object

It's quite deep.. how to convert the array into a ArrayDataProvider in yii


Solution

I think there's no out of the box way. Your CustomAudienceBean object's properties are protected, so you can't access them directly. You have to extend the class if there are no public methods.

You have 2 options,

  1. Extend CustomAudienceBean class and define a method to return all the properties you need. Then iterate your dataset and build the array for CArrayDataProvider

  2. Extend the CArrayDataProvider and feed your array of objects. Then inside your custom ArrayDataProvider you can extract the properties from CustomAudienceBean object



Answered By - Gihan
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing