0

For the purpose of using PHP to automate the creation of custom URLs that will be placed in the Pages Module, I'm first retrieving and decoding the whole block of encoded, serialized data in the exp_sites table and the site_pages column.

All is well when fetching the string from the site_pages column and assigning it to a variable like $decode_this_string.

All is again well when I get the list of URLs with PHP like so:

$site_pages = unserialize(base64_decode($decode_this_string));
$the_uris = $site_pages[1]["uris"];

When I var_dump $the_uris, I get output that looks like this, where I see string length, the page_uri, and the associated entry ID for each.

array(236) { [23]=> string(13) "/tools/index/" [36]=> string(8) "/voting/" [48]=> string(13) "/links/index/" [100]=> string(19) "/supporters/thanks/" [119]=> string(15) "/cancel/return/" [222]=> string(10) "/pressroom" ...

That's normal. But what I'd like to do is plunk this into a two-dimensional array where I can manipulate the Pages entries as rows (and can then sort them, search through them, add to them, delete them).

However, I'm confused how to break the rows down further. I can loop through them this way:

<ul>
<?php foreach ($the_uris as $uri): ?>
    echo '<li>' . $uri . '</li>';
<?php endforeach; ?>
</ul>

...but this way, all I can seem to output is the page_uri, not the entry associated with the page_uri. This is the output from the code above.

/tools/index
/voting/
/links/index

etc. In other words, I don't know how to break the row $uri into its related key and value (or "pair" of entry_id and page_uri, if that's a better way of describing it).

Is there a way to do this, so I can grab the entry_id along with the page_uri?

0

I figured out the answer just a few minutes after posting.

<?php foreach ($the_uris as $key => $val) { ?>
    <tr>
        <td><?php echo "[" . $key . "] => " . $val; ?></td>
    </tr>
<?php } ?>

This is great. Now I can just find the page URI through a simple array with an entry ID key, like:

<?php echo 'entry id 36 = ' . $the_uris[36]; ?>

which outputs:

/voting/
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.