0

Is there a way to use hash mark in route pattern? I tried to use backslash before hash mark \#, but no result.

My code:

use Phalcon\Mvc\Router\Group;

$gr = new Group([
  'module' => 'home',
]);

$gr->addPost("/item/view/([0-9]*)/#([0-9]*)", [
  'module'     => 'item',
  'controller' => 'view',
  'firstId' => 1,
  'secondId' => 2,
])->setName('item:view:hash');

$router->mount($gr);

Usage:

echo $this->url->get(['for' => 'item:view:hash', 'firstId' => 1, 'secondId' => 2])

gives me a correct url: /item/view/1/#2, but I receive a warning:

Unknown modifier '('

Is there a way to remove warnings, to use the hash mark in the right way? Thanks in advance.

Ulysse BN
  • 10,116
  • 7
  • 54
  • 82
Lena
  • 84
  • 6

1 Answers1

1

Nothing after the # mark is sent to the server, so including it in a server-side route doesn't do anything. The fragment/anchor is client-side only.

ceejayoz
  • 176,543
  • 40
  • 303
  • 368
  • Thank you for the answer. Yes, I know that, and I need the second parameter for the client feature. I just need to build that link using Phalcon route if possible – Lena Jun 07 '19 at 14:26
  • @Elena I suspect Phalcon is using the `#` character as their regex delineator (as it should never be in a route). Try escaping it with a \ - `"/item/view/([0-9]*)/\#([0-9]*)"` – ceejayoz Jun 07 '19 at 14:28
  • Thank you for your answer! Unfortunately, it didn't help (it breaks the route), but I agree that I shouldn't use it. I'll rewrite the functionality. Thank you for your help – Lena Jun 11 '19 at 07:43