开发者

Kohana 3 -> Checking if page with (URI) exists

开发者 https://www.devze.com 2023-02-01 16:11 出处:网络
With Kohana 3, I would like to get to know if a page with a by the user entered URI exists. So basically the user enters an URI, and I will say if it will give a (404) error or not.

With Kohana 3, I would like to get to know if a page with a by the user entered URI exists. So basically the user enters an URI, and I will say if it will give a (404) error or not.

I already tried this, but it didn't work:

<?php
 public function action_test_uri()
 {
    $r = Request::factory('this/uri/is/not/leading/to/a/valid/page');
    $test = $r->status;
    $test = ($test == 404) ? 'THIS PAGE DOESN\'T EXISTS' : '开发者_StackOverflow中文版THIS PAGE EXISTS';
    die($test);
 }
?>

Unfortunately this outputs 'THIS PAGE EXISTS'.

Is there anyone who does know the solution?

Thanks


Retrieve all routes and test if any of them matches the URI. However, this does not tell you how the controller handles the URI. The controller might as well generate a 404, so the only sure way is to actually retrieve the page referred to by the URI.

0

精彩评论

暂无评论...
验证码 换一张
取 消