App::url() don't work for page in child dir
Current page URL: /invoices/sale.php
// button in page like this
$b = new \atk4\ui\Button(['Export Invoice Lines', 'tiny right labeled basic black', 'icon'=>'download']);
$cb = $b->add(new \atk4\ui\Callback());
$b->on('click', new \atk4\ui\jsExpression('document.location=[]', [$cb->getURL()]));
$cb->getURL() returns /sale.php?...callback...parameters..., but should return /invoices/sale.php?...
That's because in Api->url() it calculates $this->page as basename($uri) = 'sale' and if $page[0] page url is not explicitly passed (like callback getURL() does) it returns $page[0] = $this->page = basename($uri) = 'sale'. I expect invoices/sale here not basename.
url() has never worked for nested pages. If you think about it, without a proper router that is able to determine root of the project it's not even possible.
I suggest to workaround with this:
function url(..) {
return '/path/to/app/'.parent::url(..);
}
Well... maybe. But that makes App->url() usable only for quite limited use-cases and tiny projects where all pages are in same hierarchy level :(
well that's how it is. We can always integrate a router+front controller+location-aware url through an add-on. We can have a hook inside url to fully override it or perhaps even extend App.
Remember that this logic is NOT required in integration with Wordpress.
The URLs should be reworked completely and also handled relative to the project/application dir. Calculating the relative path is complex - see https://github.com/symfony/http-foundation/blob/004b479100c784da10038ad40147e0854396c694/Request.php#L1791 - and therefore the symfony/http-foundation package should be used for it.
There should be a possibility to get the base project URL and the relative path (path after the project URL incl. query part).
some work started in https://github.com/atk4/ui/blob/d8b145f8/src/App.php#L633
repro:
var_dump($app->url(__FILE__));
I think we can detect absolute path easily and run it thru App::createRequestPathFromLocalPath()