Oziris
April 24, 2017, 8:50pm
1
Hi
I am trying to deliver an array of dates inside structure field. My problem is that my function doesn’t return any value, and I don’t have any errors. What did I miss ?
visite:
label: Visites
type: structure
entry: >
Date : <h1>{{date}}</h1>
fields:
date:
label: Date
type: date
My function is
<?php
$items = $site->find('visites-guidees')->visite()->toStructure();
$visite = [];
foreach($items as $item) {
$visite[] = $item->date('Y-m-d');
}
?>
What I’m looking for :
<?php $visite = array('2017-05-27, 2017-04-17, 2017-03-22, ... ');?>
What does dump($items)
return?
Oziris
April 24, 2017, 9:05pm
3
Ouch, I just don’t know how to do it. Where do I have to write this ?
Just after you define $items
… I think you are not addressing the right page, but that is guesswork, therefore I would like to see the result of dump()
And then you can do the same for $visite
.
<?php
$items = $site->find('visites-guidees')->visite()->toStructure();
dump($items);
$visite = [];
foreach($items as $item) {
$visite[] = $item->date('Y-m-d');
}
dump($visite);
?>
Oziris
April 24, 2017, 9:10pm
5
So I tried and then
And I have
(
[0] => Structure Object
(
[date] => Field Object
(
[page] => visites-guidees
[key] => date
[value] => 2017-05-25
)
)
[1] => Structure Object
(
[date] => Field Object
(
[page] => visites-guidees
[key] => date
[value] => 2017-05-26
)
)
)
Array
(
[0] => Y-m-d
[1] => Y-m-d
)
Ok, so that’s fine. Now dump($visite)
. You don’t have to echo the dump… see edit of my last post.
Oziris
April 24, 2017, 9:16pm
7
I replied just during you typed your response…So I edited too. My previous reply is from the code you previously edited
I used
<?php
$items = $site->find('visites-guidees')->visite()->toStructure();
dump($items);
$visite = [];
foreach($items as $item) {
$visite[] = $item->date('Y-m-d');
}
dump($visite);
?>
I can see that is not correct :
Array
(
[0] => Y-m-d
[1] => Y-m-d
)
1 Like
Yes, that’s not correct, but that’s a bit strange. It should look like this:
Array
(
[0] => 2017-05-25
[1] => 2017-05-16
)
Have you set a different date handler in your config? If you have set it to strftime
that might be the reason why this happens.
Oziris
April 24, 2017, 9:27pm
10
Yes, I have it, and all my document is running with c::set('date.handler', 'strftime');
Oziris
April 24, 2017, 9:30pm
12
Well, once again, you solved my problem, thank you very much.
Best