0

What is the correct way on PHP, Phalcon Framework on how to optionally escape a forward slash "/" that has optional parameter at the end.

I want to achieve:

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

My regex:

Working, but without params :(

transactions[/]{0,1}

Not working, on server logs, it's adding "transactions/2" even if the url does not have it.

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

Working, but explicitly instruct to have a param at the end. How can I have an optional "/" forward slash.

transactions/{param}

Appreciate any advise.

Thanks

Louie Miranda
  • 1,071
  • 1
  • 20
  • 36
  • In Phalcon do you specify the delimiter? – chris85 Oct 15 '15 at 03:55
  • 2
    The author "Phalcon" on the forum suggested on a similar note to just use two routes one with param, the other does not have it. https://forum.phalconphp.com/discussion/2823/optional-param-in-phalcon-router#C24517 – Louie Miranda Oct 15 '15 at 03:56

1 Answers1

0

Assuming you have a TransactionsController with an indexAction(), try defining two routes like explained :

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

$router->add(
    "/transactions",
    array(
        "controller" => "transactions",
        "action"     => "index",
    )
);
50bbx
  • 1
  • 2