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

Router::extensions(['pdf']) not respected #147

Closed
dereuromark opened this issue Jan 24, 2016 · 7 comments
Closed

Router::extensions(['pdf']) not respected #147

dereuromark opened this issue Jan 24, 2016 · 7 comments
Labels

Comments

@dereuromark
Copy link
Member

using routes=>true on Plugin::load() should enable pdf as extension.
So I only have Router::extensions(['json']); in my own app routes.php because those should be merged.
And debugging the CakePdf routes.php file shows: They are merged:

[
    (int) 0 => 'json',
    (int) 1 => 'pdf'
]

But then, the controller does not work:

The action action.pdf is not defined in DemoController

It seems something in 3.1 goes wrong here regarding extension handling in routes.
I suspect that the routes parsing happens before the extensions could all be set when relying on plugin routes.php files.

@ndm2
Copy link
Contributor

ndm2 commented Jan 28, 2016

Router::scope() reads the currently set global extensions and passes them on into the route builder, and from there on the global extensions aren't touched anymore. That means that the Router::plugins() call which in the app template is by default placed after the route definitions, comes too late.

AFAIR that's not a 3.1 specific problem, it was always like that, as it's a feature so that global extensions cannot randomly "pollute" routes.

@dereuromark
Copy link
Member Author

In that case https://github.com/FriendsOfCake/CakePdf/blob/master/config/routes.php#L4 is highly misleading and should be removed.

@ndm2
Copy link
Contributor

ndm2 commented Jan 28, 2016

I would have suggested that too. In any case an explanation would be required in the docs, so promoting the "correct", manual approach of adding extensions is probably the way to go (not sure if one could call moving the Router::plugins() call upwards "wrong", but it could certainly in turn introduce other problems).

ndm2 pushed a commit to ndm2/CakePdf that referenced this issue Feb 8, 2016
By default, using plugin routes to register extensions for application
routes happens too late, which will cause the automatic PDF view
functionality to not be triggered for URLs with the `pdf` extension.
Therefore the extension is best to be registered manually when needed.

Resolves FriendsOfCake#147
@Isengo1989
Copy link

So is there an solution for this problem? I already "wasted" more then 10 hours in that issue.

@ndm2
Copy link
Contributor

ndm2 commented Feb 8, 2016

Call me again after 72 hours of no sleep, no food, and no water, when you're one step away from setting your computer on fire and chopping it into pieces with a rabid weasel tied to a spiked mace, you're not real developer until then :)

On a serious note, check the updated readme: https://github.com/ndm2/CakePdf/blob/ffbeddfccb61f57262248fe5ab8de3769fedb34b/README.md#setup

@Isengo1989
Copy link

OMG! This works! I had it at the end at some desperate point...... But it actually needs to be above the routes scope.

Thanks so much! I am flipping my shit!

@ADmad
Copy link
Member

ADmad commented Mar 18, 2016

Closing as PR #153 is open to update readme.

@ADmad ADmad closed this as completed Mar 18, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants