2017-01-15 3 views
1

ajouter ce code dans le contrôleur de bas de page opencart:PHP Warning: Chaîne illégale de décalage dans la liste de tableau

$data['tags_name'] = array('inux','ubunuto','php'); 
    foreach ($data['tags_name'] as $tag) { 
     $data['tags'][] = array(
      'title' => $tag['tags_name'], 
      'href' => $this->url->link('product/search', 'tag=' . $tag['tags_name']) 
     ); 
    } 

Et d'ajouter cette ligne footer.tpl:

<?php foreach ($tags as $tag) { ?> 
    <li><a class="" target="" href="<?php echo $tag['href']; ?>"><?php echo $tag['title']; ?></a></li> 
<?php } ?> 

Je vérifie la sortie: print_r($tags); résultat est:

Array ([0] => Array ([title] => i [href] => http://localhost/opencart/index.php?route=product/search&tag=i) 
[1] => Array ([title] => u [href] => http://localhost/opencart/index.php?route=product/search&tag=u) 
[2] => Array ([title] => p [href] => http://localhost/opencart/index.php?route=product/search&tag=p)) 

Je vois seulement le premier mot de balises comme: i OuOup Et cette erreur:

Warning: Illegal string offset 'tags_name' in /Applications/XAMPP/xamppfiles/htdocs/opencart/vqmod/vqcache/vq2-system_storage_modification_catalog_controller_common_footer.php

Comment ne peut corriger cette erreur et la sortie ?!

+1

Modifier le '$ tag ['tags_name']' simplement '' $ tag' -> ''title' => $ tag, 'href' => $ this-> url -> link ('product/search', 'tag ='. $ tag'. '['tags_name']' est la clé du tableau de '$ data', mais puisque vous avez' foreach ($ data ['tags_name'] comme $ tag) 'vous êtes déjà à l'intérieur de la clé' ['tags' ']' – Sean

+0

@Sean: Bien sûr que U. fonctionne maintenant – NewCod3r

Répondre

0

Votre tableau est tableau multidimensionnel de arrays.Try comme ..

<?php foreach ($tags as $key=>$value) { ?> 
    <li><a class="" target="" href="<?php echo $value['href']; ?>"><?php echo $value['title']; ?></a></li> 
<?php } ?> 

Voici par exemple:

<?php 
$arr = array(array('title'=>'i','href'=>'http://localhost/opencart/index.php?route=product/search&tag=i'),array('title'=>'u','href'=>'http://localhost/opencart/index.php?route=product/search&tag=u'),array('title'=>'p','href'=>' http://localhost/opencart/index.php?route=product/search&tag=p')); 
//print_r($arr); 

foreach($arr as $key=>$value){ ?> 
    <li><a class="" target="" href="<?php echo $value['href']; ?>"><?php echo $value['title'];?></a></li> 

<?php } ?> 
0
<?php 
$data['tags_name'] = array('inux','ubunuto','php'); 
    foreach ($data['tags_name'] as $tag) { 
     $data['tags'][] = array(
      'title' => $tag['tags_name'], 
      'href' => $this->url->link('product/search', 'tag=' . $tag['tags_name']) 
     ); 
    } 
?> 

ce qui est $tag['tag_name']? Vous pouvez echo cela et vous trouverez quelque chose