0

PHP 上的正确方法是什么,Phalcon 框架如何选择性地转义末尾有可选参数的正斜杠“ / ”。

我想实现:

http://example.com/transactions
http://example.com/transactions/
http://example.com/transactions/1
http://example.com/transactions/2

我的正则表达式:

工作,但没有参数:(

transactions[/]{0,1}

不起作用,在服务器日志上,即使 url 没有它,它也会添加“transactions/2”。

transactions[/]{0,1}{param}

工作,但明确指示最后有一个参数。我怎样才能有一个可选的“ / ”正斜杠。

transactions/{param}

感谢任何建议。

谢谢

4

1 回答 1

0

假设您有一个带有 indexAction() 的 TransactionsController,请尝试定义两个路由,如下所示:

<?php
$router->add(
    "/transactions/{param}",
    array(
        "controller" => "transactions",
        "action"     => "index",
    )
);

$router->add(
    "/transactions",
    array(
        "controller" => "transactions",
        "action"     => "index",
    )
);
于 2015-10-28T10:09:23.877 回答