4

I add a view contains three display page,and the page urls are:

  1. questions
  2. questions/my
  3. questions/unanswered

but when I visit the url questions/s12dsdd ,It display the questions page list all questions,how to display a 404 page ? I found none settings in views.

of course we can handle it in code,but not a good one....

other desciptions:

What he asks (I believe) is how to have 3 displays in one view and with [placeholder], [placeholder/versionone], [placeholder/versiontwo] URLs respectively and get a 404 on [placeholder/somethingrandom]. The second part of the URL does not seem to be an actual argument such as %nid. It's just a literal representation within the URL of what the display is meant to provide. :) @magtak

1

2 Answers 2

6

You can create two views. In one, using questions as URL, you add "Content: Nid" as contextual filter, and use the following settings for that contextual filter.

  • In When the filter value is NOT in the URL

    • Select Display all results for the specified field

    screenshot

  • In When the filter value IS in the URL or a default is provided

    • Select Specify validation criteria
    • As Validator, select Content
    • As Action to take if filter value does not validate select Show "Page not found"

    screenshot

The other view, using questions/mine as URL, would use "Content: Author uid" as criteria, and use a default value taken from the user currently logged-in.

8
  • I don't think the values in arg(1) are contextual filters. They are simply paths who's arg(0) seems to be the same with the first display's path. If he uses your configuration the nid will never be provided and will result in a 404 page every time.
    – user5005
    Commented Oct 25, 2012 at 13:05
  • I created a view using the setting I described, and it works. The only difference is that I used articles as path. With example.com/articles, I see all the nodes; with example.com/articles/19, I see that node (when it exists), or the 404 error page (where the node doesn't exist). With example.com/articles/mine I see all articles I created/edited. (This is another view I created.) In the first view, I used articles as URL, not articles/%.
    – avpaderno
    Commented Oct 25, 2012 at 16:00
  • The view works because, when no value is given for the contextual filter, it shows all the nodes.
    – avpaderno
    Commented Oct 25, 2012 at 16:02
  • You created 2 views, not 2 displays in a single view such as the OP asked, right? What he asks (I believe) is how to have 3 displays in one view and with [placeholder], [placeholder/versionone], [placeholder/versiontwo] URLs respectively and get a 404 on [placeholder/somethingrandom]. The second part of the URL does not seem to be an actual argument such as %nid. It's just a literal representation within the URL of what the display is meant to provide. :)
    – user5005
    Commented Oct 26, 2012 at 7:07
  • I could not use two displays, as with example.com/articles/mine I used "Content: Author uid" as filter criterion, and in Views 7.x-3, a filter criterion is added to all the displays. With example.com/articles/19, there is no need of such criterion. The OP didn't say he doesn't want to use a new view, though.
    – avpaderno
    Commented Oct 26, 2012 at 14:41
3

Drupal 7 – Show page not found if view argument exists http://eureka.ykyuen.info/2012/02/24/drupal-7-show-page-not-found-if-view-argument-exists/ Posted on February 24, 2012 Assume we have a Views page which does not have a contextual filter setting and the view path is /eureka. If you provide an argument in the url such as /eureka/abc, the argument is ignored and the Views page will return all view rows. But sometimes we may want to show the user a page not found instead of return all rows. This can be done by adding a Global: Null argument in the contextual filter.

  1. Add a Global: Null input in the View Contextual Filters settings.

  2. Check the Specify validation criteria option and select PHP Code as validator.

if (empty($argument)) { return TRUE; } else { return FALSE; }

Done =)

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.