Jump to content

Check if we're on the main board page


Go to solution Solved by CodingJungle,

Recommended Posts

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.

Link to comment
Share on other sites

  • Solution
Posted (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 by CodingJungle
Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...