Upgrade from rc4 to rc5 (CCK is at rc10).

Table view is giving

warning: Invalid argument supplied for foreach() in /srv/www/www.rscounselling.co.uk/htdocs/sites/all/modules/views/theme/views-view-... on line 22.

Seems like $rows is empty? The SQL that the view is running is:

SELECT node.nid AS nid FROM node node WHERE (node.status <> 0) AND (node.type in ('link'))

And in the db that is showing me

+-----+
| nid |
+-----+
|  27 | 
|  28 | 
|  29 | 
|  30 | 
+-----+

.

View cache has been cleared - no change.

Here's the view:

$view = new view;
$view->name = 'Links';
$view->description = 'External Links';
$view->tag = '';
$view->view_php = '';
$view->base_table = 'node';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('fields', array(
  'field_url_url' => array(
    'label' => '',
    'link_to_node' => 0,
    'label_type' => 'none',
    'format' => 'default',
    'multiple' => array(
      'group' => TRUE,
      'multiple_number' => '',
      'multiple_from' => '',
      'multiple_reversed' => FALSE,
    ),
    'exclude' => 0,
    'id' => 'field_url_url',
    'table' => 'node_data_field_url',
    'field' => 'field_url_url',
    'relationship' => 'none',
  ),
));
$handler->override_option('filters', array(
  'status' => array(
    'operator' => '=',
    'value' => 1,
    'group' => '0',
    'exposed' => FALSE,
    'expose' => array(
      'operator' => FALSE,
      'label' => '',
    ),
    'id' => 'status',
    'table' => 'node',
    'field' => 'status',
    'relationship' => 'none',
  ),
  'type' => array(
    'id' => 'type',
    'table' => 'node',
    'field' => 'type',
    'value' => array(
      'link' => 'link',
    ),
  ),
));
$handler->override_option('access', array(
  'type' => 'none',
  'role' => array(),
  'perm' => '',
));
$handler->override_option('title', 'Links');
$handler->override_option('header_format', '1');
$handler->override_option('footer_format', '1');
$handler->override_option('empty_format', '1');
$handler->override_option('items_per_page', '10');
$handler->override_option('use_pager', TRUE);
$handler->override_option('style_plugin', 'table');
$handler->override_option('style_options', array(
  'grouping' => '',
  'override' => 1,
  'sticky' => 0,
  'order' => 'asc',
  'columns' => array(
    'field_url_url' => 'field_url_url',
  ),
  'info' => array(
    'field_url_url' => array(
      'sortable' => 0,
      'separator' => '',
    ),
  ),
  'default' => '-1',
));
$handler = $view->new_display('page', 'Page', 'page_1');
$handler->override_option('path', 'links');
$handler->override_option('menu', array(
  'type' => 'normal',
  'title' => 'Links',
  'weight' => 0,
  'name' => 'navigation',
));
$handler->override_option('tab_options', array(
  'type' => 'none',
  'title' => NULL,
  'weight' => NULL,
));
CommentFileSizeAuthor
#15 318944-table_error.patch392 bytesdawehner

Comments

chrissearle’s picture

Could well be a link field issue - see http://drupal.org/node/319463

merlinofchaos’s picture

Status: Active » Postponed (maintainer needs more info)

Yea, I can't get this to happen with another field. If it only happens with the link field, something may be broken in the handler causing the field to not appear. Because there are no OTHER fields it's causing an error.

chrissearle’s picture

OK - we'll follow it on http://drupal.org/node/319463

Do I understand you correctly that you did manage to repeat it with link?

merlinofchaos’s picture

I didn't; I don't have link.module installed. =)

smithmb’s picture

Status: Active » Postponed (maintainer needs more info)

I can still reproduce this with 6.x-2.2 without using any extra modules except CCK, Views 2, and some content types. It appears to happen when the visitor doesn't have access to view any of the resulting rows in the view. It only comes up in table style. I'm using nodereference for the fields to display in the view.

Also, changing permissions on the referenced nodes (to allowing anonymous views of the ref'd nodes) doesn't make the problem go away until I rebuild the permissions cache.

I think this is probably somewhat widespread, given the results to:
http://www.google.com/search?q=views-view-table.tpl.php+"line+22"

smithmb’s picture

Version: 6.x-2.0-rc5 » 6.x-2.2
Status: Postponed (maintainer needs more info) » Active
tomsherlock’s picture

Title: Table style crashes when no fields are visible due to permissions. » Invalid argument in views-view-table.tpl.php

I too am experiencing the invalid argument in views-view-table.tpl.php.

I first experienced the error in 6.x-2.5, then i upgraded to 6.x-2.6 thinking the upgrade might clear up the problem. I have Drupal 6.12.

I created a view displaying fields from node type 'profile'. I did not realized that i had a problem until i attempted to display the view with an authenticated user without admin rights. In other words, when i display the view from userid 1, i have no problem.

I do NOT have the link.module enabled.
I have read http://drupal.org/node/319463. Doesn't apply.

I have traced the code once with eclipse and got lost. I will try again. I cannot find in the code the text: "warning: Invalid argument supplied for foreach()".

I have the view accessible only to authenticated users. So that the menu item does not show when logged out. Originally i had set permission for anonymous to access all views. Thinking this was the problem i removed that permission from anonymous. I move that permission to authenticated user. I still had the problem. I removed the permission from authenticated user and have it set only for the editor role. I still have the problem.

I thought clearing the cache might help. It didn't.

I thought the data might be corrupt. The profile type i created has a firstname field and lastname field. I had one profile in which these fields were blank. I got rid of that profile. i still have the problem.

The view and sql appear to reference a table that does not exist on the database: node_data_field_firstname. Is this a placeholder for the table
content_type_profile and field field_firstname_value?

Hopefully someone can assist.

-Tom

SELECT node.nid AS nid,
   node_data_field_firstname.field_firstname_value AS node_data_field_firstname_field_firstname_value,
   node.type AS node_type,
   node.vid AS node_vid,
   node_data_field_firstname.field_lastname_value AS node_data_field_firstname_field_lastname_value
 FROM node node 
 LEFT JOIN content_type_profile node_data_field_firstname ON node.vid = node_data_field_firstname.vid
 WHERE node.type in ('profile')
   ORDER BY node_data_field_firstname_field_lastname_value ASC

$view = new view;
$view->name = 'PTA_Parents';
$view->description = 'Directory of PTA Parents';
$view->tag = 'directory, PTA, parents,';
$view->view_php = '';
$view->base_table = 'node';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('fields', array(
  'field_firstname_value' => array(
    'label' => 'First Name',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'strip_tags' => 0,
      'html' => 0,
    ),
    'link_to_node' => 1,
    'label_type' => 'widget',
    'format' => 'default',
    'multiple' => array(
      'group' => TRUE,
      'multiple_number' => '',
      'multiple_from' => '',
      'multiple_reversed' => FALSE,
    ),
    'exclude' => 0,
    'id' => 'field_firstname_value',
    'table' => 'node_data_field_firstname',
    'field' => 'field_firstname_value',
    'relationship' => 'none',
  ),
  'field_lastname_value' => array(
    'label' => 'Last Name',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'strip_tags' => 0,
      'html' => 0,
    ),
    'link_to_node' => 1,
    'label_type' => 'widget',
    'format' => 'default',
    'multiple' => array(
      'group' => TRUE,
      'multiple_number' => '',
      'multiple_from' => '',
      'multiple_reversed' => FALSE,
    ),
    'exclude' => 0,
    'id' => 'field_lastname_value',
    'table' => 'node_data_field_lastname',
    'field' => 'field_lastname_value',
    'relationship' => 'none',
  ),
));
$handler->override_option('filters', array(
  'type' => array(
    'operator' => 'in',
    'value' => array(
      'profile' => 'profile',
    ),
    'group' => '0',
    'exposed' => FALSE,
    'expose' => array(
      'operator' => FALSE,
      'label' => '',
    ),
    'id' => 'type',
    'table' => 'node',
    'field' => 'type',
    'relationship' => 'none',
  ),
));
$handler->override_option('access', array(
  'type' => 'none',
));
$handler->override_option('cache', array(
  'type' => 'none',
));
$handler->override_option('use_pager', 'mini');
$handler = $view->new_display('page', 'Parents Directory', 'page_1');
$handler->override_option('access', array(
  'type' => 'role',
  'role' => array(
    '2' => 2,
  ),
));
$handler->override_option('title', 'Parents Directory');
$handler->override_option('items_per_page', 20);
$handler->override_option('use_pager', '1');
$handler->override_option('style_plugin', 'table');
$handler->override_option('style_options', array(
  'grouping' => '',
  'override' => 1,
  'sticky' => 1,
  'order' => 'asc',
  'columns' => array(
    'field_firstname_value' => 'field_firstname_value',
    'field_lastname_value' => 'field_lastname_value',
  ),
  'info' => array(
    'field_firstname_value' => array(
      'sortable' => 0,
      'separator' => '',
    ),
    'field_lastname_value' => array(
      'sortable' => 1,
      'separator' => '',
    ),
  ),
  'default' => 'field_lastname_value',
));
$handler->override_option('path', 'directory/pta/parents');
$handler->override_option('menu', array(
  'type' => 'none',
  'title' => '',
  'description' => '',
  'weight' => 0,
  'name' => 'navigation',
));
$handler->override_option('tab_options', array(
  'type' => 'none',
  'title' => '',
  'description' => '',
  'weight' => 0,
));



tomsherlock’s picture

Version: 6.x-2.2 » 6.x-2.6
Status: Postponed (maintainer needs more info) » Active

One difference i've noticed is that the $header variable is uninitialized when the user's role is authorized user only. However, $header is initialized with two elements (one for each column header) for userid 1 (admin).

I'm trying now to figure out where $header is declared and initialized and why the difference in user should matter.

<table class="<?php print $class; ?>">
  <?php if (!empty($title)) : ?>
    <caption><?php print $title; ?></caption>
  <?php endif; ?>
  <thead>
    <tr>
      <?php foreach ($header as $field => $label): ?>
        <th class="views-field views-field-<?php print $fields[$field]; ?>">
          <?php print $label; ?>
        </th>
      <?php endforeach; ?>
    </tr>
  </thead>
  <tbody>
    <?php foreach ($rows as $count => $row): ?>
      <tr class="<?php print implode(' ', $row_classes[$count]); ?>">
        <?php foreach ($row as $field => $content): ?>
          <td class="views-field views-field-<?php print $fields[$field]; ?>">
            <?php print $content; ?>
          </td>
        <?php endforeach; ?>
      </tr>
    <?php endforeach; ?>
  </tbody>
</table>
tomsherlock’s picture

Sigh.

I figured out the cause of my problem.

tomsherlock’s picture

Status: Active » Closed (fixed)

O.K.

I just couldn't help myself. So often i see solution seekers saying "figured it out. I don't need your help anymore" and leaving the rest of us high and dry.

Well i am deservedly embarrassed (and grateful [greatful]) to say that my mountain is but a molehill: i simply forgot to set the correct view permissions for the fields under User Management >> Permissions.

I would be nice if eventually, the error thrown in this case would be something along the lines of "permission to view field denied. Check permissions under User Management or check with the webmaster/administrator". Not sure where such an error would be generated, views or core. Perhaps this requires another level of abstraction, or coding to check for such things such as that permission set for a role, etc.

Thanks for all your past and ongoing efforts and contributions, Earl. It's miles above anything i may ever be able to do Drupal. That i may be proven erroneous.

Tom

merlinofchaos’s picture

Title: Invalid argument in views-view-table.tpl.php » Table style crashes when no fields are visible due to permissions.
Status: Closed (fixed) » Active

Thanks very much for the explanation. It's always very helpful to know why things went wrong.

You're right that table should possibly be a little nicer about this kind of failure. It shouldn't be too difficult. Changing title to update status. This could use a patch.

tjjacobsen’s picture

Title: Invalid argument in views-view-table.tpl.php » Table style crashes when no fields are visible due to permissions.

Just did the same thing! I wouldve wasted a couple of hours trying to figure it out. Thanks a ton.

-Todd

merlinofchaos’s picture

Issue tags: +views worthwhile features

Adding a tag.

ThaiGringo’s picture

I found I had done the same thing and forgot to assign permissions to my CCK fields. Your documentation of your issue helped save me time, also. Thanks.

dawehner’s picture

Status: Active » Needs review
StatusFileSize
new392 bytes

I think this should fix the php error problem

merlinofchaos’s picture

Status: Needs review » Fixed

Committed to all branches.

Status: Fixed » Closed (fixed)
Issue tags: -views worthwhile features

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