atk4 / ui

Robust and easy to use PHP Framework for Web Apps
https://atk4-ui.readthedocs.io
MIT License
440 stars 105 forks source link

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

Open DarkSide666 opened 6 years ago

DarkSide666 commented 6 years ago

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.

romaninsh commented 6 years ago

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(..);
}
DarkSide666 commented 6 years ago

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

romaninsh commented 6 years ago

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.

mvorisek commented 1 year ago

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