ui icon indicating copy to clipboard operation
ui copied to clipboard

App::url() don't work for page in child dir

Open DarkSide666 opened this issue 8 years ago • 4 comments

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.

DarkSide666 avatar Apr 05 '18 07:04 DarkSide666

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(..);
}

romaninsh avatar Apr 05 '18 12:04 romaninsh

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 :(

DarkSide666 avatar Apr 05 '18 19:04 DarkSide666

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.

romaninsh avatar Apr 07 '18 09:04 romaninsh

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).

mvorisek avatar Feb 04 '20 00:02 mvorisek

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()

mvorisek avatar Oct 03 '22 22:10 mvorisek