php - Correct regex for param after an optional forward slash -
what correct way on php, phalcon framework on how optionally escape forward slash "/" has optional parameter @ end.
i want achieve:
http://example.com/transactions http://example.com/transactions/ http://example.com/transactions/1 http://example.com/transactions/2
my regex:
working, without params :(
transactions[/]{0,1}
not working, on server logs, it's adding "transactions/2" if url not have it.
transactions[/]{0,1}{param}
working, explicitly instruct have param @ end. how can have optional "/" forward slash.
transactions/{param}
appreciate advise.
thanks
assuming have transactionscontroller indexaction(), try defining 2 routes explained :
<?php $router->add( "/transactions/{param}", array( "controller" => "transactions", "action" => "index", ) ); $router->add( "/transactions", array( "controller" => "transactions", "action" => "index", ) );
Comments
Post a Comment