Oli1
February 26, 2019, 7:04am
1
Hi there,
in past I’ve used this code and it always works:
<?php if ( count($slideshow = $page->slideshow_slides()->toStructure()) ) : ?>
...
<?php endif; ?>
But since Kirby 3 it throws a error? Is this cause of PHP 7 or has this any other reasons? Is this a good workaround?
<?php if ( $slideshow = $page->slideshow_slides()->toStructure()->count() ) : ?>
...
<?php endif; ?>
There is no count()
method in the Collection class. This is probably a regression from Kirby 2 so it might be worthwile to add an issue on github for this.
Oli1
February 26, 2019, 7:40am
3
Done, I opened an Issue. It doesn’t hurt that it’s not working anymore, but maybe someone else get similar problems during the upgrade from K2 to K3
texnixe
February 26, 2019, 9:13am
4
Count()
is a simple PHP method, it is not a Kirby 3 method nor was there a Kirby 2 count helper.
You can still use count() like this:
count($slideshow = $page->slideshow_slides()->toStructure()->toArray())
but your second example is what I would use anyway, using the count()
method of the collection class
<?php if ( $slideshow = $page->slideshow_slides()->toStructure()->count() ) : ?>
...
<?php endif; ?>
Oli1
February 26, 2019, 11:34am
5
Thanks so much. I only wonder why it was working in K2 but not in K3 anymore?
In v2 our Collection class implemented the countable interface http://php.net/manual/de/class.countable.php I think we can bring this back.
Oli1
February 26, 2019, 1:22pm
7
Would be awesome. However, if it’s deprecated it’s also no problem to use the Kirby Function