Cannot access empty property fatal error when adding field

adcworks - October 30, 2006 - 15:39
Project:Views
Version:5.x-1.6
Component:Code
Category:bug report
Priority:critical
Assigned:Unassigned
Status:closed
Description

I created a basic content type for a news article with created date, title, abstract and story. I created a view page and block for this content type.

I cannot add more than 1 field for the view (which is a List type). I can add the Node: Title but when I add Node: Created Date Drupal errors with a fatal error - cannot access empty property views.module 1283 which is

return check_plain($data->$field['queryname']);

And vice versa, I can remove the Node: Title, and then add Node: Created Date, but then when I try to readd Node: Title, the same error occurs.

#1

merlinofchaos - November 13, 2006 - 05:09

This is rather odd.

The views editor isn't tied to the node type, since it really knows nothing about that; having a filter on the node type shouldn't impact the rest of it.

As for the actual error you're getting...I'm at a loss. Can you duplicate this error on a basic Drupal installation? I've never seen anything like this, and I've been adding stuff to views for testing purposes all day on 2 different installations.

#2

merlinofchaos - December 9, 2006 - 02:30
Status:active» closed

Without some way to duplicate, I'm closing the issue.

#3

brenda003 - December 3, 2007 - 08:34
Version:4.7.x-1.x-dev» 5.x-1.6
Status:closed» active

I am able to recreate this error like so:

Export view from one site (local) and import to the other (staging). The field node title is not imported properly and doesn't show up on the imported view.

<?php
  $view
= new stdClass();
 
$view->name = 'block_green_news';
 
$view->description = '';
 
$view->access = array (
);
 
$view->view_args_php = '';
 
$view->page = FALSE;
 
$view->page_title = '';
 
$view->page_header = '';
 
$view->page_header_format = '1';
 
$view->page_footer = '';
 
$view->page_footer_format = '1';
 
$view->page_empty = '';
 
$view->page_empty_format = '1';
 
$view->page_type = 'node';
 
$view->url = '';
 
$view->use_pager = TRUE;
 
$view->nodes_per_page = '10';
 
$view->block = TRUE;
 
$view->block_title = 'Green News';
 
$view->block_header = '';
 
$view->block_header_format = '1';
 
$view->block_footer = '';
 
$view->block_footer_format = '1';
 
$view->block_empty = '';
 
$view->block_empty_format = '1';
 
$view->block_type = 'list';
 
$view->nodes_per_block = '5';
 
$view->block_more = FALSE;
 
$view->block_use_page_header = FALSE;
 
$view->block_use_page_footer = FALSE;
 
$view->block_use_page_empty = FALSE;
 
$view->sort = array (
  );
 
$view->argument = array (
  );
 
$view->field = array (
    array (
     
'tablename' => 'node',
     
'field' => 'title',
     
'label' => '',
     
'handler' => 'views_handler_field_nodelink',
     
'options' => 'link',
    ),
    array (
     
'tablename' => 'node',
     
'field' => 'body',
     
'label' => '',
     
'handler' => 'views_handler_field_teaser',
    ),
    array (
     
'tablename' => 'node',
     
'field' => 'link',
     
'label' => '',
     
'options' => 'more',
    ),
  );
 
$view->filter = array (
    array (
     
'tablename' => 'node',
     
'field' => 'status',
     
'operator' => '=',
     
'options' => '',
     
'value' => '1',
    ),
    array (
     
'tablename' => 'term_node_1',
     
'field' => 'tid',
     
'operator' => 'AND',
     
'options' => '',
     
'value' => array (
 
0 => '6',
),
    ),
  );
 
$view->exposed_filter = array (
  );
 
$view->requires = array(node, term_node_1);
 
$views[$view->name] = $view;
?>

Then, add the Node: Title field manually on the new site. Fine, works. Click on the up arrow to put it at the top and this error occurs, at line 1270.

Going back into the view and saving it first, then repeating the last step, results in no error.

#4

Christefano - December 24, 2007 - 11:05

I'm encountering this, too. Thanks for the writeup, brenda003.

#5

bjaspan - December 28, 2007 - 18:26

I am also encountering this error. I'm using Views 5.x-1.6 with the small patch from http://drupal.org/node/165611 to fix
double %-replacement bug.

The bug occurs when I add a second field to a view without saving the view after adding the first field (to be precise, the view already has one field; I select a second, press Add field, select a third, press Add field, and get the error). The errors occurs in theme_views_handle_field() because the $field argument is undefined. In my case, this function is called from theme_views_view_list(). In that function $view->field is an array of fields. In the example I just gave, index 1 of $view->field (ie: the first field I am adding, which will be the second of the view) is an empty array. Index 2, the field I am trying to add when the error occurs, is correct.

Let me know if I can be of more help.

#6

bjaspan - December 28, 2007 - 18:29

Hmmm. One other comment: The view I am editing in this example has a List Block that is displayed on the view editing page itself (in fact, on all pages). I note this because it seems odd to me that a field I have added to the view in edit mode but have not yet saved is showing up in theme_views_view_list() at all. Perhaps the problem is that the unsaved changes are getting absorbed into the saved, displayed view.

#7

catch - January 9, 2008 - 20:26
Priority:normal» critical

bumping this to critical - lots of people having issues with list views

#8

jt_jones - January 22, 2008 - 23:17

subscribing

Update: I can not reproduce this error on my local dev site using Views 5.x-1.6 or the latest dev version (5.x-1.x-dev, January 21, 2008).

The live site that gets the fatal error (at line 1270) was originally a 4.7 site that has been upgraded to 5.x. Could the fact that it's an upgraded site have anything to do with this issue?

Drupal 5.6
Views 5.x-1.6
Apache 2.2.4
PHP 5.2.4
MySQL 5.0.45

#9

jt_jones - January 23, 2008 - 19:48

First, I'm not a programmer so don't really know what I'm doing, PHP wise.

I copied my live site over to my computer...I really need to get this working, so I did a Google search on "Cannot access empty property". The top link - http://agaricdesign.com/cannot-access-empty-property - suggest a problem with using $node->field syntax on a variable that doesn't exist. Noticing that his "field" doesn't have a $, I removed the $ from field on line 1270 (Views module). Hey, error message is gone with a new message > Same error on Views Calc (which I'm checking out) line 401. I removed the $ from the first "field" on VC line 401 and no more error messages.

Views Calc Table and List view are working correctly (at least locally). Could someone with more programming experience (who might understand what removing the $ actually does) look into this?

Thanks

#10

jt_jones - January 31, 2008 - 16:19

Last update - Drupal 5.7 has fixed the fatal error message for me (without editing the Views module). I'm not sure what fixed it. Any one else have any success?

#11

patriciaoakim - March 31, 2008 - 03:34

Hi,

I'm also having the same problem. I think it has to do with trying to do more than one change in the field section. I got my block to work by selecting only 1 field, saving it, coming back to edit it, and adding a new field. But if I try to do more than one change at once, such as adding a new field and reordering them, the same error occurs:
"Fatal error: Cannot access empty property in /home/polivox/public_html/modules/views/views.module on line 1270".

So, it seems that a workaround would be making only one change at a time. Here is the line 1270:
"return check_plain($data->$field['queryname']);".

The other thing that I noticed is related to the theme. I'm using SpreadFirefox and I switched to BlueMarine just to test it and it worked just fine!

Jt_Jones, I'm not a programmer either, but I'm almost a 100% positive that what you are changing in your code is the variable identification in php. The $ before a word is what creates variables in php.

I'm copying here the code that I got from the export link on the view. I don't know how much helpful that is, but I thought it could be worth it.

I hope we can figure out the problem and fix it!
Patricia

$view = new stdClass();
$view->name = 'imagino';
$view->description = 'Fórum Imagino';
$view->access = array (
);
$view->view_args_php = '';
$view->page = FALSE;
$view->page_title = '';
$view->page_header = '';
$view->page_header_format = '1';
$view->page_footer = '';
$view->page_footer_format = '1';
$view->page_empty = '';
$view->page_empty_format = '1';
$view->page_type = 'node';
$view->url = '';
$view->use_pager = TRUE;
$view->nodes_per_page = '10';
$view->block = TRUE;
$view->block_title = 'Fórum Imagino';
$view->block_header = 'This is is my really brilliant introductory paragraph. Hope you like it.';
$view->block_header_format = '1';
$view->block_footer = 'Thanks for looking at my Cool Block. It\'s my first one.';
$view->block_footer_format = '1';
$view->block_empty = '';
$view->block_empty_format = '1';
$view->block_type = 'list';
$view->nodes_per_block = '5';
$view->block_more = FALSE;
$view->block_use_page_header = TRUE;
$view->block_use_page_footer = TRUE;
$view->block_use_page_empty = FALSE;
$view->sort = array (
array (
'tablename' => 'node',
'field' => 'created',
'sortorder' => 'DESC',
'options' => 'normal',
),
);
$view->argument = array (
);
$view->field = array (
array (
'tablename' => 'node',
'field' => 'title',
'label' => '',
'handler' => 'views_handler_field_nodelink',
'options' => 'link',
),
array (
'tablename' => 'node_data_field_futuro_desejado',
'field' => 'field_futuro_desejado_value',
'label' => '',
'handler' => 'content_views_field_handler_group',
'options' => 'default',
),
);
$view->filter = array (
array (
'tablename' => 'node_data_field_situacao_atual',
'field' => 'field_situacao_atual_value_like',
'operator' => '=',
'options' => '',
'value' => '',
),
);
$view->exposed_filter = array (
);
$view->requires = array(node, node_data_field_futuro_desejado, node_data_field_situacao_atual);
$views[$view->name] = $view;

#12

mikepeterson - May 29, 2008 - 16:05

Subscribing

I'm having the same problem.

I'm running Drupal 5.3, Views 5.x-1.6, and the theme Salamander.

#13

Ehud - June 22, 2008 - 07:05

Having the same problem with Drupal 5.7.
Does anyone know a workaround for this problem?

#14

Harry Slaughter - June 26, 2008 - 22:02

Same problem here.

In my case, I can reproduce it by adding a field to a (block only) view and then immediately deleting it.

Of course, the bug is probably tied to my particular view :) I'll attach the exported view in case...

AttachmentSize
buggy_view.txt 1.79 KB

#15

R.Hendel - July 23, 2008 - 10:05

quite mysterious:
we have had the same problem, which healed by itself over night. ;-)
We could watch that error but could not not reproduce it later.
A workaround seems to be, to add new criteria etc after saving the view once.

Ralf Hendel
comm-press Webdienstleistungen

#16

sun - September 20, 2008 - 22:40
Status:active» postponed (maintainer needs more info)

@all: Please check whether this bug might be tied to your PHP version.

#17

seanr - January 22, 2009 - 22:28

Just got this while adding a field to a new cloned view. I saved the view, went back in, and was able to add the field just fine.

Views 5.x-1.x-dev
PHP 5.1.6

#18

pianomansam - March 5, 2009 - 16:10

Ran into this problem today trying to add a cck image field and moving it to the top field spot. bjaspan's comment about having the view show up on the edit page made me realize my view was showing up too. Once I removed the block, everything saved normally.

#19

jeroenk2 - March 10, 2009 - 13:47

Pianomansam, thanks, you solved my problem!

#20

esmerel - September 10, 2009 - 22:42
Status:postponed (maintainer needs more info)» closed

No update for more than 30 days.

 
 

Drupal is a registered trademark of Dries Buytaert.