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

merlinofchaos’s picture

Status: Active » Postponed (maintainer needs more info)

I 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).

Comunic-art’s picture

Hi,

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:

<?php
$view = views_get_view('blogs');
$view->set_arguments(array('all'));
$view->execute();
$view_result_count = count($view->result);
if ($view_result_count > 0) {
  print l(t('Link to show'), 'path/of/view');
}
?>

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!

dawehner’s picture

Status: Postponed (maintainer needs more info) » Active

You miss pre_execute.

dawehner’s picture

Status: Active » Fixed

So this is fixed

Status: Fixed » Closed (fixed)

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