Closed (fixed)
Project:
Views (for Drupal 7)
Version:
6.x-2.7
Component:
Views Data
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
24 Nov 2009 at 16:42 UTC
Updated:
13 Jul 2010 at 21:20 UTC
Hi,
I have a link in my web which leads to a Views page. This link only should to be showed if the views has result for current user.
To do the checking I create a instance of the view and I try to get the result.
$view = views_get_view('name_of_view');
$view->set_arguments(array('argument'));
$view->execute();
$view_result_count = count($view->result);
if ($view_result_count > 0) {
print l(t('Link to show'), 'path/of/view');
}
This method works properly but when user tries to login and it fails (when the page shows a red box with text like "login failed"), this method always return as result 0 items.
Comments
Comment #1
merlinofchaos commentedI don't see a question here and I don't see what you think is wrong. You show some code of yours, but you don't explain anything about the view, which is where the bug you're theoretically reporting must be. You should read the submission guidelines about submitting bug reports. (Also, this is probably more along the lines of a support request, as I don't even see what you think is a bug here).
Comment #2
Comunic-art commentedHi,
I'm sorry for the poor description of the problem.
I created a view through Views UI. This view, named "blogs", has a display of type "page". This view lists all nodes of type "blog" limited to 10 items.
When user visits the URL of the page display of view, the view works properly.
So, I have in a block a link to this view but I want to be showed only when view has items (result count is greater than 0).
I try the following code and it works fine:
This code is working very fine. I built the view and I executed it, so I can get the count result.
But this code does not work fine when user login fails and, in general, when Drupal shows errors messages through drupal_set_message('text', 'error') function. When Drupal shows an error message result count is always 0.
Why Drupal error messages conflicts with views building process? How can I solve it?
Thanks!
Comment #3
dawehnerYou miss pre_execute.
Comment #4
dawehnerSo this is fixed