Jump to content

Featured Replies

Posted

Hello,

can we check if we're on the default page (for example with changed default app)?

 

Thanks in advance!

Solved by CodingJungle

Go to solution

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;
  • Author

Hm, load app info every page check isn't much efficient. Maybe someone else has better idea.

But thanks for sharing it!

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.

  • Solution

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 by CodingJungle

  • Author
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!

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.

  • Author

Thanks, I didn't know about it.

Recently Browsing 0

  • No registered users viewing this page.