Jump to content

find() and custom WireArray with subfields / sub-properties


pwFoo
 Share

Recommended Posts

Hi,

I build a new module and try to convert data into WireArray to get the PW API benefits (find('selector'), get('selector'), ...).

Some code to my tests...

Define a custom WireArray class

class CustomWireArray extends WireArray
{
    public $toStringString  = '';

    public function __toString() {
        return $this->toStringString;
    }
    
    public function __get($key) {
        return $this->$key;
    }

    public function __set($key, $value) {
        $this->$key = $value;
    }
}

Create a new CustomWireArray

$customWireArray = new customWireArray();

Create a new array item

$item = new customWireArray();

// set properties to $item...

$customWireArray->add($item); // add to the customWireArray

So far it works fine. No problem to find() / get() properties from the $customWireArray, but I need sub-items  :rolleyes:

Tested it with a sub-customWireArray and also a simple stdClass, but it won't work with PW find() / get().

Is there a way to get sub-properties work with something like that?

$result = $customWireArray->find('property.subfield=MyValue');
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...