Jump to content

Convert Pages with image field to php array / json


pwFoo
 Share

Recommended Posts



I try to convert PageArrray / Page objects to a php array and next step to json.

 

It works fine if I try to output the object by "print_r" with all the (private) attributes, but how to convert a image (field) to an array with the private attributes url, ?

 

Example of converted page with image field

(
    [id] => 1022
    [name] => test2
    [status] => 1
    [numChildren] => 0
    [sort] => 5
    [sortfield] => sort
    [modified_users_id] => 41
    [created_users_id] => 41
    [created] => 1545857760
    [modified] => 1545939813
    [published] => 1545857760
    [title] => test2
    [email] => 
    [image] => Array
        (
            [tux.png] => stdClass Object
                (
                    [basename] => tux.png
                    [description] => Test1233 beschreibung bild
                    [tags] => 
                    [formatted] => 1
                    [modified] => 1545939810
                    [created] => 1545939726
                )

        )

)(
    [id] => 1022
    [name] => test2
    [status] => 1
    [numChildren] => 0
    [sort] => 5
    [sortfield] => sort
    [modified_users_id] => 41
    [created_users_id] => 41
    [created] => 1545857760
    [modified] => 1545939813
    [published] => 1545857760
    [title] => test2
    [email] => 
    [image] => Array
        (
            [tux.png] => stdClass Object
                (
                    [basename] => tux.png
                    [description] => Test1233 beschreibung bild
                    [tags] => 
                    [formatted] => 1
                    [modified] => 1545939810
                    [created] => 1545939726
                )

        )

)(
    [id] => 1022
    [name] => test2
    [status] => 1
    [numChildren] => 0
    [sort] => 5
    [sortfield] => sort
    [modified_users_id] => 41
    [created_users_id] => 41
    [created] => 1545857760
    [modified] => 1545939813
    [published] => 1545857760
    [title] => test2
    [email] => 
    [image] => Array
        (
            [tux.png] => stdClass Object
                (
                    [basename] => tux.png
                    [description] => Test1233 beschreibung bild
                    [tags] => 
                    [formatted] => 1
                    [modified] => 1545939810
                    [created] => 1545939726
                )

        )

)(
    [id] => 1022
    [name] => test2
    [status] => 1
    [numChildren] => 0
    [sort] => 5
    [sortfield] => sort
    [modified_users_id] => 41
    [created_users_id] => 41
    [created] => 1545857760
    [modified] => 1545939813
    [published] => 1545857760
    [title] => test2
    [email] => 
    [image] => Array
        (
            [tux.png] => stdClass Object
                (
                    [basename] => tux.png
                    [description] => Test1233 beschreibung bild
                    [tags] => 
                    [formatted] => 1
                    [modified] => 1545939810
                    [created] => 1545939726
                )

        )

)(
    [id] => 1022
    [name] => test2
    [status] => 1
    [numChildren] => 0
    [sort] => 5
    [sortfield] => sort
    [modified_users_id] => 41
    [created_users_id] => 41
    [created] => 1545857760
    [modified] => 1545939813
    [published] => 1545857760
    [title] => test2
    [email] => 
    [image] => Array
        (
            [tux.png] => stdClass Object
                (
                    [basename] => tux.png
                    [description] => Test1233 beschreibung bild
                    [tags] => 
                    [formatted] => 1
                    [modified] => 1545939810
                    [created] => 1545939726
                )

        )

)(
    [id] => 1022
    [name] => test2
    [status] => 1
    [numChildren] => 0
    [sort] => 5
    [sortfield] => sort
    [modified_users_id] => 41
    [created_users_id] => 41
    [created] => 1545857760
    [modified] => 1545939813
    [published] => 1545857760
    [title] => test2
    [email] => 
    [image] => Array
        (
            [tux.png] => stdClass Object
                (
                    [basename] => tux.png
                    [description] => Test1233 beschreibung bild
                    [tags] => 
                    [formatted] => 1
                    [modified] => 1545939810
                    [created] => 1545939726
                )

        )

)(
    [id] => 1022
    [name] => test2
    [status] => 1
    [numChildren] => 0
    [sort] => 5
    [sortfield] => sort
    [modified_users_id] => 41
    [created_users_id] => 41
    [created] => 1545857760
    [modified] => 1545939813
    [published] => 1545857760
    [title] => test2
    [email] => 
    [image] => Array
        (
            [tux.png] => stdClass Object
                (
                    [basename] => tux.png
                    [description] => Test1233 beschreibung bild
                    [tags] => 
                    [formatted] => 1
                    [modified] => 1545939810
                    [created] => 1545939726
                )

        )

)(
    [id] => 1022
    [name] => test2
    [status] => 1
    [numChildren] => 0
    [sort] => 5
    [sortfield] => sort
    [modified_users_id] => 41
    [created_users_id] => 41
    [created] => 1545857760
    [modified] => 1545939813
    [published] => 1545857760
    [title] => test2
    [email] => 
    [image] => Array
        (
            [tux.png] => stdClass Object
                (
                    [basename] => tux.png
                    [description] => Test1233 beschreibung bild
                    [tags] => 
                    [formatted] => 1
                    [modified] => 1545939810
                    [created] => 1545939726
                )

        )

)(
    [id] => 1022
    [name] => test2
    [status] => 1
    [numChildren] => 0
    [sort] => 5
    [sortfield] => sort
    [modified_users_id] => 41
    [created_users_id] => 41
    [created] => 1545857760
    [modified] => 1545939813
    [published] => 1545857760
    [title] => test2
    [email] => 
    [image] => Array
        (
            [tux.png] => stdClass Object
                (
                    [basename] => tux.png
                    [description] => Test1233 beschreibung bild
                    [tags] => 
                    [formatted] => 1
                    [modified] => 1545939810
                    [created] => 1545939726
                )

        )

)(
    [id] => 1022
    [name] => test2
    [status] => 1
    [numChildren] => 0
    [sort] => 5
    [sortfield] => sort
    [modified_users_id] => 41
    [created_users_id] => 41
    [created] => 1545857760
    [modified] => 1545939813
    [published] => 1545857760
    [title] => test2
    [email] => 
    [image] => Array
        (
            [tux.png] => stdClass Object
                (
                    [basename] => tux.png
                    [description] => Test1233 beschreibung bild
                    [tags] => 
                    [formatted] => 1
                    [modified] => 1545939810
                    [created] => 1545939726
                )

        )

)(
    [id] => 1022
    [name] => test2
    [status] => 1
    [numChildren] => 0
    [sort] => 5
    [sortfield] => sort
    [modified_users_id] => 41
    [created_users_id] => 41
    [created] => 1545857760
    [modified] => 1545939813
    [published] => 1545857760
    [title] => test2
    [email] => 
    [image] => Array
        (
            [tux.png] => stdClass Object
                (
                    [basename] => tux.png
                    [description] => Test1233 beschreibung bild
                    [tags] => 
                    [formatted] => 1
                    [modified] => 1545939810
                    [created] => 1545939726
                )

        )

)(
    [id] => 1022
    [name] => test2
    [status] => 1
    [numChildren] => 0
    [sort] => 5
    [sortfield] => sort
    [modified_users_id] => 41
    [created_users_id] => 41
    [created] => 1545857760
    [modified] => 1545939813
    [published] => 1545857760
    [title] => test2
    [email] => 
    [image] => Array
        (
            [tux.png] => stdClass Object
                (
                    [basename] => tux.png
                    [description] => Test1233 beschreibung bild
                    [tags] => 
                    [formatted] => 1
                    [modified] => 1545939810
                    [created] => 1545939726
                )

        )

)(
    [id] => 1022
    [name] => test2
    [status] => 1
    [numChildren] => 0
    [sort] => 5
    [sortfield] => sort
    [modified_users_id] => 41
    [created_users_id] => 41
    [created] => 1545857760
    [modified] => 1545939813
    [published] => 1545857760
    [title] => test2
    [email] => 
    [image] => Array
        (
            [tux.png] => stdClass Object
                (
                    [basename] => tux.png
                    [description] => Test1233 beschreibung bild
                    [tags] => 
                    [formatted] => 1
                    [modified] => 1545939810
                    [created] => 1545939726
                )

        )

)(
    [id] => 1022
    [name] => test2
    [status] => 1
    [numChildren] => 0
    [sort] => 5
    [sortfield] => sort
    [modified_users_id] => 41
    [created_users_id] => 41
    [created] => 1545857760
    [modified] => 1545939813
    [published] => 1545857760
    [title] => test2
    [email] => 
    [image] => Array
        (
            [tux.png] => stdClass Object
                (
                    [basename] => tux.png
                    [description] => Test1233 beschreibung bild
                    [tags] => 
                    [formatted] => 1
                    [modified] => 1545939810
                    [created] => 1545939726
                )

        )

)(
    [id] => 1022
    [name] => test2
    [status] => 1
    [numChildren] => 0
    [sort] => 5
    [sortfield] => sort
    [modified_users_id] => 41
    [created_users_id] => 41
    [created] => 1545857760
    [modified] => 1545939813
    [published] => 1545857760
    [title] => test2
    [email] => 
    [image] => Array
        (
            [tux.png] => stdClass Object
                (
                    [basename] => tux.png
                    [description] => Test1233 beschreibung bild
                    [tags] => 
                    [formatted] => 1
                    [modified] => 1545939810
                    [created] => 1545939726
                )

        )

)(
    [id] => 1022
    [name] => test2
    [status] => 1
    [numChildren] => 0
    [sort] => 5
    [sortfield] => sort
    [modified_users_id] => 41
    [created_users_id] => 41
    [created] => 1545857760
    [modified] => 1545939813
    [published] => 1545857760
    [title] => test2
    [email] => 
    [image] => Array
        (
            [tux.png] => stdClass Object
                (
                    [basename] => tux.png
                    [description] => Test1233 beschreibung bild
                    [tags] => 
                    [formatted] => 1
                    [modified] => 1545939810
                    [created] => 1545939726
                )

        )

)(
    [id] => 1022
    [name] => test2
    [status] => 1
    [numChildren] => 0
    [sort] => 5
    [sortfield] => sort
    [modified_users_id] => 41
    [created_users_id] => 41
    [created] => 1545857760
    [modified] => 1545939813
    [published] => 1545857760
    [title] => test2
    [email] => 
    [image] => Array
        (
            [tux.png] => stdClass Object
                (
                    [basename] => tux.png
                    [description] => Test1233 beschreibung bild
                    [tags] => 
                    [formatted] => 1
                    [modified] => 1545939810
                    [created] => 1545939726
                )

        )

)(
    [id] => 1022
    [name] => test2
    [status] => 1
    [numChildren] => 0
    [sort] => 5
    [sortfield] => sort
    [modified_users_id] => 41
    [created_users_id] => 41
    [created] => 1545857760
    [modified] => 1545939813
    [published] => 1545857760
    [title] => test2
    [email] => 
    [image] => Array
        (
            [tux.png] => stdClass Object
                (
                    [basename] => tux.png
                    [description] => Test1233 beschreibung bild
                    [tags] => 
                    [formatted] => 1
                    [modified] => 1545939810
                    [created] => 1545939726
                )

        )

)(
    [id] => 1022
    [name] => test2
    [status] => 1
    [numChildren] => 0
    [sort] => 5
    [sortfield] => sort
    [modified_users_id] => 41
    [created_users_id] => 41
    [created] => 1545857760
    [modified] => 1545939813
    [published] => 1545857760
    [title] => test2
    [email] => 
    [image] => Array
        (
            [tux.png] => stdClass Object
                (
                    [basename] => tux.png
                    [description] => Test1233 beschreibung bild
                    [tags] => 
                    [formatted] => 1
                    [modified] => 1545939810
                    [created] => 1545939726
                )

        )

)(
    [id] => 1022
    [name] => test2
    [status] => 1
    [numChildren] => 0
    [sort] => 5
    [sortfield] => sort
    [modified_users_id] => 41
    [created_users_id] => 41
    [created] => 1545857760
    [modified] => 1545939813
    [published] => 1545857760
    [title] => test2
    [email] => 
    [image] => Array
        (
            [tux.png] => stdClass Object
                (
                    [basename] => tux.png
                    [description] => Test1233 beschreibung bild
                    [tags] => 
                    [formatted] => 1
                    [modified] => 1545939810
                    [created] => 1545939726
                )

        )

)(
    [id] => 1022
    [name] => test2
    [status] => 1
    [numChildren] => 0
    [sort] => 5
    [sortfield] => sort
    [modified_users_id] => 41
    [created_users_id] => 41
    [created] => 1545857760
    [modified] => 1545939813
    [published] => 1545857760
    [title] => test2
    [email] => 
    [image] => Array
        (
            [tux.png] => stdClass Object
                (
                    [basename] => tux.png
                    [description] => Test1233 beschreibung bild
                    [tags] => 
                    [formatted] => 1
                    [modified] => 1545939810
                    [created] => 1545939726
                )

        )

)

Missing url attribute and some more (needed) values.

 

RAW output with needed attributes:

ProcessWire\Pageimages Object
(
    [count] => 1
    

url, filename, width, ...

 

How to get the (private) attributes by detect the attribute names and get them in a foreach loop?

 

Sorry if something isn't clear... I'm in hurry and may add additional information later is needed... ?


=> /test2/ [field] => image [url] => /pw/site/assets/files/1022/ [path] => C:/xampp/htdocs/pw/site/assets/files/1022/ [items] => Array ( [tux.png] => Array ( [url] => /pw/site/assets/files/1022/tux.png [filename] => C:/xampp/htdocs/pw/site/assets/files/1022/tux.png [filesize] => 6705 [description] => Test1233 beschreibung bild [tags] => [created] => 2018-12-27 20:42:06 [modified] => 2018-12-27 20:43:30 [filemtime] => 2018-12-27 20:42:06 [width] => 225 [height] => 225 [suffix] => ) ) )ProcessWire\Pageimages Object ( [count] => 1

=> /test2/ [field] => image [url] => /pw/site/assets/files/1022/ [path] => C:/xampp/htdocs/pw/site/assets/files/1022/ [items] => Array ( [tux.png] => Array ( [url] => /pw/site/assets/files/1022/tux.png [filename] => C:/xampp/htdocs/pw/site/assets/files/1022/tux.png [filesize] => 6705 [description] => Test1233 beschreibung bild [tags] => [created] => 2018-12-27 20:42:06 [modified] => 2018-12-27 20:43:30 [filemtime] => 2018-12-27 20:42:06 [width] => 225 [height] => 225 [suffix] => ) ) )ProcessWire\Pageimages Object ( [count] => 1

=> /test2/ [field] => image [url] => /pw/site/assets/files/1022/ [path] => C:/xampp/htdocs/pw/site/assets/files/1022/ [items] => Array ( [tux.png] => Array ( [url] => /pw/site/assets/files/1022/tux.png [filename] => C:/xampp/htdocs/pw/site/assets/files/1022/tux.png [filesize] => 6705 [description] => Test1233 beschreibung bild [tags] => [created] => 2018-12-27 20:42:06 [modified] => 2018-12-27 20:43:30 [filemtime] => 2018-12-27 20:42:06 [width] => 225 [height] => 225 [suffix] => ) ) )ProcessWire\Pageimages Object ( [count] => 1

=> /test2/ [field] => image [url] => /pw/site/assets/files/1022/ [path] => C:/xampp/htdocs/pw/site/assets/files/1022/ [items] => Array ( [tux.png] => Array ( [url] => /pw/site/assets/files/1022/tux.png [filename] => C:/xampp/htdocs/pw/site/assets/files/1022/tux.png [filesize] => 6705 [description] => Test1233 beschreibung bild [tags] => [created] => 2018-12-27 20:42:06 [modified] => 2018-12-27 20:43:30 [filemtime] => 2018-12-27 20:42:06 [width] => 225 [height] => 225 [suffix] => ) ) )ProcessWire\Pageimages Object ( [count] => 1

=> /test2/ [field] => image [url] => /pw/site/assets/files/1022/ [path] => C:/xampp/htdocs/pw/site/assets/files/1022/ [items] => Array ( [tux.png] => Array ( [url] => /pw/site/assets/files/1022/tux.png [filename] => C:/xampp/htdocs/pw/site/assets/files/1022/tux.png [filesize] => 6705 [description] => Test1233 beschreibung bild [tags] => [created] => 2018-12-27 20:42:06 [modified] => 2018-12-27 20:43:30 [filemtime] => 2018-12-27 20:42:06 [width] => 225 [height] => 225 [suffix] => ) ) )
Link to comment
Share on other sites

Sorry code isn't displayed correct...

I insert just the needed part...

 

    [items] => Array
        (
            [tux.png] => Array
                (
                    [url] => /pw/site/assets/files/1022/tux.png
                    [filename] => C:/xampp/htdocs/pw/site/assets/files/1022/tux.png
                    [filesize] => 6705
                    [description] => Test1233 beschreibung bild
                    [tags] => 
                    [created] => 2018-12-27 20:42:06
                    [modified] => 2018-12-27 20:43:30
                    [filemtime] => 2018-12-27 20:42:06
                    [width] => 225
                    [height] => 225
                    [suffix] => 
                )

        )

 

Link to comment
Share on other sites

I know this thread, but isn't what I'm searching for.

Can't use explode() with single Page, just PageArray and if I try to get the image field JSON is looking like that.

[null,null,null] // all fields of a PageArray
[null,{},{}] // image field only

 

Tried explode(), getArray() and getIterator() before without success.

Link to comment
Share on other sites

1 hour ago, pwFoo said:

Can't use explode() with single Page, just PageArray

You are right. So, we convert it to a WireArray and we can use explode() ?

 

// single image field
$singleImage = $page->image;
// new WireArray for convenience
$wa = new WireArray();
// add our single image to the WireArray
$wa->add($singleImage);
// you can add all the properties you want here
$arr = $wa->explode(array('name','description','url'));
// normal array
echo '<pre> ONE IMAGE IN WIRE ARRAY ';
print_r($arr);
echo '</pre>';
// normal JSON
echo json_encode($arr);

 

getArray() won't work, as you found out since it is just an array with objects in it. 

Link to comment
Share on other sites

If I try to get all attributes (explode without param) it doesn't work. The result should be a array with all attributes, but it's just

            [image] => Array
                (
                    [0] => stdClass Object
                        (
                            [0] => ProcessWire\ProcessWire Object
                                (
                                    [hooks] => Array
                                        (
                                            [after ProcessWire::finished] => Template->hookFinished() in Template.php
                                        )

                                )

                        )

                )

 

Testing some more ways (getKeys() + foreach for example...) to get all the attributes to a plain array...

Link to comment
Share on other sites


Some more tests without success...

 

Object is fine:

ProcessWire\Pageimages Object
(
    [count] => 1
    

 => /test2/
    [field] => image
    [url] => /pw/site/assets/files/1022/
    [path] => C:/xampp/htdocs/pw/site/assets/files/1022/
    [items] => Array
        (
            [tux.png] => Array
                (
                    [url] => /pw/site/assets/files/1022/tux.png
                    [filename] => C:/xampp/htdocs/pw/site/assets/files/1022/tux.png
                    [filesize] => 6705
                    [description] => Test1233 beschreibung bild
                    [tags] => 
                    [created] => 2018-12-27 20:42:06
                    [modified] => 2018-12-27 20:43:30
                    [filemtime] => 2018-12-27 20:42:06
                    [width] => 225
                    [height] => 225
                    [suffix] => 
                )

        )

)
ProcessWire\Pageimages Object
(
    [count] => 1
    

 => /test2/
    [field] => image
    [url] => /pw/site/assets/files/1022/
    [path] => C:/xampp/htdocs/pw/site/assets/files/1022/
    [items] => Array
        (
            [tux.png] => Array
                (
                    [url] => /pw/site/assets/files/1022/tux.png
                    [filename] => C:/xampp/htdocs/pw/site/assets/files/1022/tux.png
                    [filesize] => 6705
                    [description] => Test1233 beschreibung bild
                    [tags] => 
                    [created] => 2018-12-27 20:42:06
                    [modified] => 2018-12-27 20:43:30
                    [filemtime] => 2018-12-27 20:42:06
                    [width] => 225
                    [height] => 225
                    [suffix] => 
                )

        )

)
ProcessWire\Pageimages Object
(
    [count] => 1
    

 => /test2/
    [field] => image
    [url] => /pw/site/assets/files/1022/
    [path] => C:/xampp/htdocs/pw/site/assets/files/1022/
    [items] => Array
        (
            [tux.png] => Array
                (
                    [url] => /pw/site/assets/files/1022/tux.png
                    [filename] => C:/xampp/htdocs/pw/site/assets/files/1022/tux.png
                    [filesize] => 6705
                    [description] => Test1233 beschreibung bild
                    [tags] => 
                    [created] => 2018-12-27 20:42:06
                    [modified] => 2018-12-27 20:43:30
                    [filemtime] => 2018-12-27 20:42:06
                    [width] => 225
                    [height] => 225
                    [suffix] => 
                )

        )

)
ProcessWire\Pageimages Object
(
    [count] => 1
    

 => /test2/
    [field] => image
    [url] => /pw/site/assets/files/1022/
    [path] => C:/xampp/htdocs/pw/site/assets/files/1022/
    [items] => Array
        (
            [tux.png] => Array
                (
                    [url] => /pw/site/assets/files/1022/tux.png
                    [filename] => C:/xampp/htdocs/pw/site/assets/files/1022/tux.png
                    [filesize] => 6705
                    [description] => Test1233 beschreibung bild
                    [tags] => 
                    [created] => 2018-12-27 20:42:06
                    [modified] => 2018-12-27 20:43:30
                    [filemtime] => 2018-12-27 20:42:06
                    [width] => 225
                    [height] => 225
                    [suffix] => 
                )

        )

)
ProcessWire\Pageimages Object
(
    [count] => 1
    

 => /test2/
    [field] => image
    [url] => /pw/site/assets/files/1022/
    [path] => C:/xampp/htdocs/pw/site/assets/files/1022/
    [items] => Array
        (
            [tux.png] => Array
                (
                    [url] => /pw/site/assets/files/1022/tux.png
                    [filename] => C:/xampp/htdocs/pw/site/assets/files/1022/tux.png
                    [filesize] => 6705
                    [description] => Test1233 beschreibung bild
                    [tags] => 
                    [created] => 2018-12-27 20:42:06
                    [modified] => 2018-12-27 20:43:30
                    [filemtime] => 2018-12-27 20:42:06
                    [width] => 225
                    [height] => 225
                    [suffix] => 
                )

        )

)

 

Try to convert it with WireArray (first print_r shows the output above! With all fields and items array)

                    print_r($value);
                    $wa =newWireArray();
                    $wa->add($value);
                    print_r($wa->explode());

 

Result

Array
(
    [0] => 
)

It's easy to output all the needed data, but not to get it to an array or object...?? ?

Link to comment
Share on other sites


Again the code / post isn't shown correct... I split it up again... Forum bug??

 

                    print_r($value);
                    $wa =newWireArray();
                    $wa->add($value);
                    print_r($wa->explode());

 

First print_r

ProcessWire\Pageimages Object
(
    [count] => 1
    

 => /test2/
    [field] => image
    [url] => /pw/site/assets/files/1022/
    [path] => C:/xampp/htdocs/pw/site/assets/files/1022/
    [items] => Array
        (
            [tux.png] => Array
                (
                    [url] => /pw/site/assets/files/1022/tux.png
                    [filename] => C:/xampp/htdocs/pw/site/assets/files/1022/tux.png
                    [filesize] => 6705
                    [description] => Test1233 beschreibung bild
                    [tags] => 
                    [created] => 2018-12-27 20:42:06
                    [modified] => 2018-12-27 20:43:30
                    [filemtime] => 2018-12-27 20:42:06
                    [width] => 225
                    [height] => 225
                    [suffix] => 
                )

        )

)
ProcessWire\Pageimages Object
(
    [count] => 1
    

 => /test2/
    [field] => image
    [url] => /pw/site/assets/files/1022/
    [path] => C:/xampp/htdocs/pw/site/assets/files/1022/
    [items] => Array
        (
            [tux.png] => Array
                (
                    [url] => /pw/site/assets/files/1022/tux.png
                    [filename] => C:/xampp/htdocs/pw/site/assets/files/1022/tux.png
                    [filesize] => 6705
                    [description] => Test1233 beschreibung bild
                    [tags] => 
                    [created] => 2018-12-27 20:42:06
                    [modified] => 2018-12-27 20:43:30
                    [filemtime] => 2018-12-27 20:42:06
                    [width] => 225
                    [height] => 225
                    [suffix] => 
                )

        )

)
ProcessWire\Pageimages Object
(
    [count] => 1
    

 => /test2/
    [field] => image
    [url] => /pw/site/assets/files/1022/
    [path] => C:/xampp/htdocs/pw/site/assets/files/1022/
    [items] => Array
        (
            [tux.png] => Array
                (
                    [url] => /pw/site/assets/files/1022/tux.png
                    [filename] => C:/xampp/htdocs/pw/site/assets/files/1022/tux.png
                    [filesize] => 6705
                    [description] => Test1233 beschreibung bild
                    [tags] => 
                    [created] => 2018-12-27 20:42:06
                    [modified] => 2018-12-27 20:43:30
                    [filemtime] => 2018-12-27 20:42:06
                    [width] => 225
                    [height] => 225
                    [suffix] => 
                )

        )

)
ProcessWire\Pageimages Object
(
    [count] => 1
    

 => /test2/
    [field] => image
    [url] => /pw/site/assets/files/1022/
    [path] => C:/xampp/htdocs/pw/site/assets/files/1022/
    [items] => Array
        (
            [tux.png] => Array
                (
                    [url] => /pw/site/assets/files/1022/tux.png
                    [filename] => C:/xampp/htdocs/pw/site/assets/files/1022/tux.png
                    [filesize] => 6705
                    [description] => Test1233 beschreibung bild
                    [tags] => 
                    [created] => 2018-12-27 20:42:06
                    [modified] => 2018-12-27 20:43:30
                    [filemtime] => 2018-12-27 20:42:06
                    [width] => 225
                    [height] => 225
                    [suffix] => 
                )

        )

)
ProcessWire\Pageimages Object
(
    [count] => 1
    

 => /test2/
    [field] => image
    [url] => /pw/site/assets/files/1022/
    [path] => C:/xampp/htdocs/pw/site/assets/files/1022/
    [items] => Array
        (
            [tux.png] => Array
                (
                    [url] => /pw/site/assets/files/1022/tux.png
                    [filename] => C:/xampp/htdocs/pw/site/assets/files/1022/tux.png
                    [filesize] => 6705
                    [description] => Test1233 beschreibung bild
                    [tags] => 
                    [created] => 2018-12-27 20:42:06
                    [modified] => 2018-12-27 20:43:30
                    [filemtime] => 2018-12-27 20:42:06
                    [width] => 225
                    [height] => 225
                    [suffix] => 
                )

        )

)

Ok, nice. All attributes are there... Also the needed attributes (url, ...) in "items" sub array.

Second print_r miss all the expected data?

Array
(
    [0] => 
)

 

Code with pagination in the forum ist strange... ??

Link to comment
Share on other sites


First print_r with the full object and needed data (items)

 

ProcessWire\Pageimages Object
(
    [count] => 1
    

 => /test2/
    [field] => image
    [url] => /pw/site/assets/files/1022/
    [path] => C:/xampp/htdocs/pw/site/assets/files/1022/
    [items] => Array
        (
            [tux.png] => Array
                (
                    [url] => /pw/site/assets/files/1022/tux.png
                    [filename] => C:/xampp/htdocs/pw/site/assets/files/1022/tux.png
                    [filesize] => 6705
                    [description] => Test1233 beschreibung bild
                    [tags] => 
                    [created] => 2018-12-27 20:42:06
                    [modified] => 2018-12-27 20:43:30
                    [filemtime] => 2018-12-27 20:42:06
                    [width] => 225
                    [height] => 225
                    [suffix] => 
                )

        )

)
ProcessWire\Pageimages Object
(
    [count] => 1
    

 => /test2/
    [field] => image
    [url] => /pw/site/assets/files/1022/
    [path] => C:/xampp/htdocs/pw/site/assets/files/1022/
    [items] => Array
        (
            [tux.png] => Array
                (
                    [url] => /pw/site/assets/files/1022/tux.png
                    [filename] => C:/xampp/htdocs/pw/site/assets/files/1022/tux.png
                    [filesize] => 6705
                    [description] => Test1233 beschreibung bild
                    [tags] => 
                    [created] => 2018-12-27 20:42:06
                    [modified] => 2018-12-27 20:43:30
                    [filemtime] => 2018-12-27 20:42:06
                    [width] => 225
                    [height] => 225
                    [suffix] => 
                )

        )

)
ProcessWire\Pageimages Object
(
    [count] => 1
    

 => /test2/
    [field] => image
    [url] => /pw/site/assets/files/1022/
    [path] => C:/xampp/htdocs/pw/site/assets/files/1022/
    [items] => Array
        (
            [tux.png] => Array
                (
                    [url] => /pw/site/assets/files/1022/tux.png
                    [filename] => C:/xampp/htdocs/pw/site/assets/files/1022/tux.png
                    [filesize] => 6705
                    [description] => Test1233 beschreibung bild
                    [tags] => 
                    [created] => 2018-12-27 20:42:06
                    [modified] => 2018-12-27 20:43:30
                    [filemtime] => 2018-12-27 20:42:06
                    [width] => 225
                    [height] => 225
                    [suffix] => 
                )

        )

)
ProcessWire\Pageimages Object
(
    [count] => 1
    

 => /test2/
    [field] => image
    [url] => /pw/site/assets/files/1022/
    [path] => C:/xampp/htdocs/pw/site/assets/files/1022/
    [items] => Array
        (
            [tux.png] => Array
                (
                    [url] => /pw/site/assets/files/1022/tux.png
                    [filename] => C:/xampp/htdocs/pw/site/assets/files/1022/tux.png
                    [filesize] => 6705
                    [description] => Test1233 beschreibung bild
                    [tags] => 
                    [created] => 2018-12-27 20:42:06
                    [modified] => 2018-12-27 20:43:30
                    [filemtime] => 2018-12-27 20:42:06
                    [width] => 225
                    [height] => 225
                    [suffix] => 
                )

        )

)
ProcessWire\Pageimages Object
(
    [count] => 1
    

 => /test2/
    [field] => image
    [url] => /pw/site/assets/files/1022/
    [path] => C:/xampp/htdocs/pw/site/assets/files/1022/
    [items] => Array
        (
            [tux.png] => Array
                (
                    [url] => /pw/site/assets/files/1022/tux.png
                    [filename] => C:/xampp/htdocs/pw/site/assets/files/1022/tux.png
                    [filesize] => 6705
                    [description] => Test1233 beschreibung bild
                    [tags] => 
                    [created] => 2018-12-27 20:42:06
                    [modified] => 2018-12-27 20:43:30
                    [filemtime] => 2018-12-27 20:42:06
                    [width] => 225
                    [height] => 225
                    [suffix] => 
                )

        )

)

Second print_r is empty. No attributes like url, description, ...

Array
(
    [0] => 
)

 

Link to comment
Share on other sites

1 hour ago, pwFoo said:

If I try to get all attributes (explode without param) it doesn't work.

You are right; It doesn't work that way. I'm not sure if that is the intended behaviour of explode() if no parameters are passed. It is returning an object; not a normal array. 

Btw, getValues() returns all the properties. However, this is an array of a Pageimage object. You'll still not be able to access the keys like in a normal array.

Link to comment
Share on other sites

I tried to automate without the need of a switch / case for different PW objects... If not possible I need some lists of properties of different ProcessWire objects...

I don't understand why some default properties like url, path, ... are private. Would be easier if accessable (as it is with a simple "$url = $obj->url").

Link to comment
Share on other sites

Hi @horst,

thanks, but that doesn't work, because the needed properties are private ☹️

You can get the value by "$obj->url". print_r works fine and show all the private keys / values, but if you convert to array / json the private properties not there.

 

I haven't found a way to automate the list of keys or any way to loop through with all the private key => value pairs (image property url and some more are private!).

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...