Hi,

when creating a 'Views Flipped Table', I'm getting the following warning on every page with this table:

Warning: Invalid argument supplied for foreach() in include() (line 39 of /var/www/drupal/sites/all/modules/views_hacks/views_flipped_table/views-flipped-table.tpl.php).

The table seems to be rendered properly.

Line 39 in views-flipped-table.tpl.php is the statement <?php foreach($row['title'] as $title): ?> from this construct:

  <?php if ($first):?>
  <thead>
    <tr class="<? echo $element; ?>">
      <th>
      </th>
      <?php foreach($row['title'] as $title): ?>
      <th>
      <?php echo $title; ?>
      </th>
      <?php endforeach; ?>
    </tr>
</thead>

I have no idea what seems to be the problem here.

Greetings, -asb

Comments

marc.groth’s picture

Hi there,

I am also getting this error and it seems that it's because there is no title set for the table... I have attached a patch to fix this (by adding an if statement to make sure that $row['title'] is an array before doing a foreach() on it - which is what the error is complaining about). The patch will need to be applied to the correct folder (i.e. views_flipped_table root folder). The change is basically:

<?php foreach($row['title'] as $title): ?>
  <th>
    <?php echo $title; ?>
  </th>
<?php endforeach; ?>

becomes

<?php if (is_array($row['title'])): ?>
  <?php foreach($row['title'] as $title): ?>
    <th>
      <?php echo $title; ?>
    </th>
  <?php endforeach; ?>
<?php endif; ?>

Is this intentional behaviour (i.e. the table has to have a title) or can this patch be applied? A check should probably be made to make sure something is an array before performing a foreach() on it, which will make sure this error isn't seen if the user decides not to give the table a title.

Many thanks,

Marc

infojunkie’s picture

Status:Active» Fixed

I fixed this using a different approach, by avoiding the title row altogether if no title field is present. Please try it 12 hours from now and let me know if it works as you expect.

infojunkie’s picture

Version:6.x-1.0-beta1» 6.x-1.x-dev

Fixed in dev of course.

marc.groth’s picture

Thanks for such a quick response infojunkie.

Do you have any idea if/when this will be rolled out into beta1? Or is it just worth using dev for now instead?

Thanks again,

Marc

infojunkie’s picture

not sure when I'll release beta2. But dev contains no major changes compared to beta1, just bug fixes, so I think you'd be safe using it.

asb’s picture

Just upgraded to views_hacks 6.x-1.x-dev and can confirm that the error no longer appears.

Thank you!

marc.groth’s picture

Thanks for the fix and information, infojunkie

Status:Fixed» Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

naught101’s picture

Project:Views Hacks» Views Flipped Table
Component:Views Flipped Table» Code