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

Call to undefined method Phalcon\Mvc\Micro\Collection::setName() #1868

Closed
cdekok opened this issue Jan 20, 2014 · 7 comments
Closed

Call to undefined method Phalcon\Mvc\Micro\Collection::setName() #1868

cdekok opened this issue Jan 20, 2014 · 7 comments

Comments

@cdekok
Copy link

cdekok commented Jan 20, 2014

It is not possible to name micro collection routes, autocomplete ide does have a method setName

$collection = new \Phalcon\Mvc\Micro\Collection();
$collection->setHandler('\Something\Controller\MyController', true);
$collection->get('/media', 'index')->setName('home');

The problem is it returns itself " \Phalcon\Mvc\Micro\Collection" instead of the "\Phalcon\Mvc\Router\RouteInterface"

@ghost
Copy link

ghost commented Jan 22, 2014

It is meant to return Phalcon\Mvc\Micro\CollectionInterface, not Phalcon\Mvc\RouterInterface: https://github.com/phalcon/cphalcon/blob/1.3.0/ext/mvc/micro/collection.c#L251

Looks like a bug in the IDE stubs.

@cdekok
Copy link
Author

cdekok commented Jan 23, 2014

@sjinks but then how is it possible to name the routes?

@ghost
Copy link

ghost commented Jan 24, 2014

Why? Phalcon\Mvc\Micro\Collection is not Phalcon\Mvc\Router\Route, they are completely different entities.

Internally, Collection is an array of arrays:

$this->_handlers = array(
    array('GET', '/route_pattern1/', 'Handler1'),
    array('POST', '/route_pattern2/', 'Handler2'),
// etc
);

Routes are created much later, when you call $app->mount($collection).

@cdekok
Copy link
Author

cdekok commented Jan 30, 2014

@sjinks To keep the interface consistent with micro application + mvc, it is possble to configure the routes and the names for the routes in the same place.

For example look at micro without collection: http://docs.phalconphp.com/en/latest/reference/routing.html#parameters-with-names
Mvc: http://docs.phalconphp.com/en/latest/reference/routing.html#parameters-with-names

Both the config for the routes and the names for the routes are in the same location, it does not seem logical for a collection to configure the routes, but set the names for them in the router itself.

What the object is internally does not really matter when it creates the actual router it could still have another array key to set the name there too to example:

 array('GET', '/route_pattern1/', 'Handler1', 'name'),

@ghost
Copy link

ghost commented Jan 30, 2014

@mech7 PR submitted, however, the syntax will differ:

Instead of

$collection->get('/media', 'index')->setName('home');

there will be

$collection->get('/media', 'index', 'home');

because the collection returns $this and can contain multiple "routes".

@cdekok
Copy link
Author

cdekok commented Jan 30, 2014

@sjinks 👍 cool thx for the pull request

@ghost
Copy link

ghost commented Feb 2, 2014

This has been merged into 1.3.0, could you pleas check and close this bug if everything works for you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants