laminas / laminas-router

Flexible routing system for HTTP and console applications
https://docs.laminas.dev/laminas-router/
BSD 3-Clause "New" or "Revised" License
34 stars 15 forks source link

Config option to set TreeRouteStack::baseUri #3

Open weierophinney opened 4 years ago

weierophinney commented 4 years ago

In every project I see people working around the Url ViewHelper not working in console context.

If there was a config option like below we could have one standardized way of solving this.

<?php // config/autoload/server-url.local.php

return [
    'server_url' => 'https://example.com'
]

Example of my latest workaround: https://stackoverflow.com/a/52248041/1899162

Secondarily we could then also use this option to make the ServerUrl ViewHelper work in console context.

@weierophinney do you want this PR for this repository or for Zend\View?


Originally posted by @Erikvv at https://github.com/zendframework/zend-router/issues/51

lon9man commented 3 months ago

6 years passed since original post.. guys, any roadmap or best practice?

who can clearly describe how to use url-helper (ServerUrl and others) inside console-application? thanks!

froschdesign commented 3 months ago

@lon9man

who can clearly describe how to use url-helper (ServerUrl and others) inside console-application?

Create and register a factory for the helper which uses the configuration. Here is an example.

lon9man commented 3 months ago

@froschdesign thanks for the reply! i checked sources.

questions:

  1. i don't see in UrlFactory something related to server_url-option in config. will it assemble routes in console successfully?
  2. i don't see laminas-mvc-view-library in the docs/google. what is it? it was made to resolve this specific issue with ServerUrl?

thanks!

froschdesign commented 3 months ago

@lon9man

  1. i don't see in UrlFactory something related to server_url-option in config. will it assemble routes in console successfully?

The Url helper does not create fully qualified domain name (absolute URL) by default and is not intended for this purpose at all. For CLI usage you can combine the ServerUrl helper and the Url helper or replace the Url helper with a custom one.

2. i don't see laminas-mvc-view-library in the docs/google. what is it? it was made to resolve this specific issue with ServerUrl?

This new / unreleased package extracts the MVC components from laminas-view with the goal of using laminas-view and its Url helpers as a standalone and providing (better) CLI support.


If you have any further questions, please use the forum or the chat.