【问题标题】:Kohana 3 -> Checking if page with (URI) existsKohana 3 -> 检查带有 (URI) 的页面是否存在
【发布时间】:2010-12-24 12:19:47
【问题描述】:

对于 Kohana 3,我想知道是否存在用户输入 URI 的页面。 所以基本上用户输入一个URI,我会说它是否会给出(404)错误。

我已经试过了,但是没有用:

<?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' : 'THIS PAGE EXISTS';
    die($test);
 }
?>

不幸的是,这会输出“此页存在”。

有谁知道解决办法吗?

谢谢

【问题讨论】:

    标签: php kohana-3


    【解决方案1】:

    检索all routes 并测试其中是否有任何matches URI。但是,这并没有告诉您控制器如何处理 URI。控制器也可以生成 404,因此唯一可靠的方法是实际检索 URI 引用的页面。

    【讨论】:

    • 我现在试了一下:$uri = 'OELOELOEthis/uri/is/not/leading/to/aaduygd gfuagufgfu/valid/page'; $routes = Route::all(); $output = '不存在!'; foreach($routes as $route) { if($route->matches($uri)) { $output = 'exists!'; } } 死($输出);但它仍然说它存在。是不可能的结论吗?
    • if($route-&gt;matches($uri)) { $output = 'exists! Route: '.Route::name($route); }
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-11
    • 2011-01-27
    • 1970-01-01
    相关资源
    最近更新 更多