Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The use route converter and beforeMatch for Router\Group #1555

Closed
sorbing opened this issue Nov 14, 2013 · 9 comments
Closed

The use route converter and beforeMatch for Router\Group #1555

sorbing opened this issue Nov 14, 2013 · 9 comments
Labels
bug A bug report status: medium Medium
Milestone

Comments

@sorbing
Copy link

sorbing commented Nov 14, 2013

I need to convert the parameter for all routed from one routes group. Maybe there is some kind of workaround. Now I have to duplicate a lot of code. Thanks.

@dreamsxin
Copy link
Contributor

Can you write a simple example? So that we can more clearly your meaning.
See https://github.com/phalcon/cphalcon/wiki/New-Feature-Request---NFR

@sorbing
Copy link
Author

sorbing commented Nov 18, 2013

The syntax is the same as for a one specified route, but I want to be able to use converter and beforeMatch for the entire group of routes:

$router = new \Phalcon\Mvc\Router();
$route_group = new \Phalcon\Mvc\Router\Group(array(
    'namespace'  => 'Controllers\GroupNa\\',
    'controller' => 'Index'
));
$route_group->setPrefix('/group');
$route_group->addGet('/{entity:[a-z_]+}/{id:[\d]+}', ['action' => 'get']);//->convert('entity', $singularize);
$route_group->addPost('/{entity:[a-z_]+}/?', ['action' => 'post']);//->convert('entity', $singularize);
// other routes
$route_group->convert('entity', $singularize);
$router->mount($route_group);

In this case, I use convert (entity, $ singularize) for the entire group of routes, Instead of apply him for each route.

@ghost
Copy link

ghost commented Nov 19, 2013

I think you can use beforeMatch() now.

I'll add support for convert().

@ghost
Copy link

ghost commented Nov 22, 2013

Could you please check now?

@sorbing
Copy link
Author

sorbing commented Nov 24, 2013

How can I convert parameters using beforeMatch () method like convert ()?

@sorbing
Copy link
Author

sorbing commented Nov 24, 2013

Also in the function-argument ($callable) to ->beforeMatch($callable) not passed parameters $uri and $route - which deprives the flexibility this method.

Example from documentation

->beforeMatch(function($uri, $route) {
  // Warning: Missing argument 1 for {closure}() in ...
  // Warning: Missing argument 2 for {closure}() in ...
});

I wrote about the problem here but this issue remained unanswered... This error in the documentation or in the code?
Thanks for the help.

@ghost
Copy link

ghost commented Nov 27, 2013

OK, will take a look.

@niden
Copy link
Member

niden commented Jan 16, 2014

Fixed in 1.3

@niden niden closed this as completed Jan 16, 2014
@sorbing
Copy link
Author

sorbing commented Jan 16, 2014

Its works. Thanks)

@niden niden added bug A bug report status: medium Medium and removed Bug - Medium labels Dec 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug report status: medium Medium
Projects
None yet
Development

No branches or pull requests

3 participants