DawPi Posted August 16, 2022 Posted August 16, 2022 Hello, can we check if we're on the default page (for example with changed default app)? Thanks in advance! The Old Man 1
IPCommerceFan Posted August 16, 2022 Posted August 16, 2022 These work for me: Default app: $defaultApp = \IPS\Application::load(\IPS\Request::i()->app)->default; Default module: $defaultModule = \IPS\Application\Module::get(\IPS\Request::i()->app, \IPS\Request::i()->module)->default; opentype 1
DawPi Posted August 16, 2022 Author Posted August 16, 2022 Hm, load app info every page check isn't much efficient. Maybe someone else has better idea. But thanks for sharing it!
CodingJungle Posted August 16, 2022 Posted August 16, 2022 a possible solution is to check the data in the \IPS\Request::i()->url() method. if it is the default app on the "homepage", then ->path should be empty: IPS\Http\Url\Friendly Object ( [url:protected] => https://dev.codingjungle.com/ [data] => Array ( [scheme] => https [host] => dev.codingjungle.com [port] => [user] => [pass] => [path] => / [query] => [fragment] => ) [queryString] => Array ( ) [hiddenQueryString] => Array ( [app] => stratagem [module] => view [controller] => projects ) [seoPagination] => [base] => front [seoTemplate] => stratagem [seoTitles] => Array ( ) [friendlyUrlComponent] => ) otherwise it will be populated with the path from the furl: IPS\Http\Url\Friendly Object ( [url:protected] => https://dev.codingjungle.com/stratagem [data] => Array ( [scheme] => https [host] => dev.codingjungle.com [port] => [user] => [pass] => [path] => /stratagem [query] => [fragment] => ) [queryString] => Array ( ) [hiddenQueryString] => Array ( [app] => stratagem [module] => view [controller] => projects ) [seoPagination] => [base] => front [seoTemplate] => stratagem [seoTitles] => Array ( ) [friendlyUrlComponent] => stratagem ) there might be a caveat to this, as i haven't fully tested this. it was something off the top of my head. 45 minutes ago, IPCommerceFan said: These work for me: Default app: $defaultApp = \IPS\Application::load(\IPS\Request::i()->app)->default; Default module: $defaultModule = \IPS\Application\Module::get(\IPS\Request::i()->app, \IPS\Request::i()->module)->default; 37 minutes ago, DawPi said: Hm, load app info every page check isn't much efficient. Maybe someone else has better idea. But thanks for sharing it! btw this could be a good method too, as applications and modules get cached, so it shouldn't cost anything noticeable in loads, well nothing more than most servers can afford to use. pukelis 1
Solution CodingJungle Posted August 16, 2022 Solution Posted August 16, 2022 (edited) plus \IPS\Dispatcher already loads these values: $app = null; $module = null; if(\IPS\Dispatcher::hasInstance()){ $dispatcher = \IPS\Dispatcher::i(); $app = $dispatcher->application; $module = $dispatcher->module; } if($app !== null && $app->default && $module->default){ //if we are here, we on the default app/module, lets do our thing } Edited August 16, 2022 by CodingJungle DawPi, The Old Man and IPCommerceFan 2 1
DawPi Posted August 16, 2022 Author Posted August 16, 2022 29 minutes ago, CodingJungle said: plus \IPS\Dispatcher already loads these values: $app = null; $module = null; if(\IPS\Dispatcher::hasInstance()){ $dispatcher = \IPS\Dispatcher::i(); $app = $dispatcher->application; $module = $dispatcher->module; } if($app !== null && $app->default && $module->default){ //if we are here, we on the default app/module, lets do our thing } That should be best solution for me. Thanks!
Ryan Ashbrook Posted August 16, 2022 Posted August 16, 2022 1 hour ago, DawPi said: Hm, load app info every page check isn't much efficient. Maybe someone else has better idea. But thanks for sharing it! For what it's worth, the current application and module is already loaded by the dispatcher (as mentioned by CodingJungle), so it won't reload it - it would just use the existing data already in memory. Additionally, applications and modules are cached in the data store so loading them on the fly should have very little effect on performance. IPCommerceFan and DawPi 2
Recommended Posts