简体   繁体   中英

Undefined index in the Slim Framework

I have an error in my code that does not identify the desphoto element which is a way to find a photo.

呃 <img src="" alt="">

This is the code where the desphoto is called <img src="{$value.desphoto}" alt=""> the code I passed is the error that happens in the cache directory of my view-cache, only my question is because it is like value1 and not just value. Look at its value in the view-cache: <?php $counter1=-1; if( isset($products) && ( is_array($products) || $products instanceof Traversable ) && sizeof($products) ) foreach( $products as $key1 => $value1 ){ $counter1++; ?> <?php $counter1=-1; if( isset($products) && ( is_array($products) || $products instanceof Traversable ) && sizeof($products) ) foreach( $products as $key1 => $value1 ){ $counter1++; ?>

If you have copy-pasted that code, you'll want to fix the syntax and see what's going on there. The closing brace for the foreach is missing.

Additionally, I have changed sizeof to count as sizeof is an alias and may be deprecated in the future, so best to not rely on it.

I've also removed the foreach as it seems it was doing the same operation. Keep it if you're doing more.

<?php 
$counter1=-1; 
if( 
    isset($products) && ( 
        is_array($products) || 
        $products instanceof Traversable 
    ) && 
    count($products) 
) 
    $counter1+=count($products);
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM