Cphalcon: router and placeholders

Created on 14 Jul 2017  路  5Comments  路  Source: phalcon/cphalcon

When text is set after a placeholder the last character is removed.

$router->add('/test/:int/test', [
    'action'        => 'index',
    'controller'    => 'index',
    'id'            => 1
])
->setName('test');

{{ link_to(['for': 'test', 'id': '123'], 'test') }}

extected:
<a href="/test/123/test">test</a>
actual:
<a href="/test/123/tes">test</a>

Details

  • Phalcon version: 3.2.1
  • PHP Version: PHP 7.0.20-1~dotdeb+8.2
  • Operating System: Debian Jessie
  • Installation type: installing via package manager
  • Zephir version (if any): 0.9.9-868cb1f92b
  • Server: Apache2

Most helpful comment

@be4i The /:int placeholder is alias for /([0-9]+). As workaround try group :int. I'll try to deal with this

PHP

$router = new Phalcon\Mvc\Router();

$router->add('/test/(:int)/test', [
    'action'        => 'index',
    'controller'    => 'index',
    'id'            => 1
])
->setName('test');

Volt

{{ link_to(['for': 'test', 'id': '123'], 'test') }}

HTML

<a href="/test/123/test">test</a>

PHP

$router = new Phalcon\Mvc\Router();

$router->add('/test/{id:[0-9]+}/test', [
    'action'     => 'index',
    'controller' => 'index',
])
->setName('test');

Volt

{{ link_to(['for': 'test', 'id': '123'], 'test') }}

HTML

<a href="/test/123/test">test</a>

PHP

$router = new Phalcon\Mvc\Router();

$router->add('/test/([0-9]+)/test', [
    'action'     => 'index',
    'controller' => 'index',
    'id'         => 1,
])
->setName('test');

Volt

{{ link_to(['for': 'test', 'id': '123'], 'test') }}

HTML

<a href="/test/123/test">test</a>

All 5 comments

Define your route as: $router->add('/test/:int/test/'
(with a trailing slash)

this is expected behavior ?

Looks weird for me. I'll try to sort out ASAP.

@be4i The /:int placeholder is alias for /([0-9]+). As workaround try group :int. I'll try to deal with this

PHP

$router = new Phalcon\Mvc\Router();

$router->add('/test/(:int)/test', [
    'action'        => 'index',
    'controller'    => 'index',
    'id'            => 1
])
->setName('test');

Volt

{{ link_to(['for': 'test', 'id': '123'], 'test') }}

HTML

<a href="/test/123/test">test</a>

PHP

$router = new Phalcon\Mvc\Router();

$router->add('/test/{id:[0-9]+}/test', [
    'action'     => 'index',
    'controller' => 'index',
])
->setName('test');

Volt

{{ link_to(['for': 'test', 'id': '123'], 'test') }}

HTML

<a href="/test/123/test">test</a>

PHP

$router = new Phalcon\Mvc\Router();

$router->add('/test/([0-9]+)/test', [
    'action'     => 'index',
    'controller' => 'index',
    'id'         => 1,
])
->setName('test');

Volt

{{ link_to(['for': 'test', 'id': '123'], 'test') }}

HTML

<a href="/test/123/test">test</a>

okay, thank you

Was this page helpful?
0 / 5 - 0 ratings