Jet\MVC

This class is the main facade of the MVC. As you already know from the router chapter, the Jet\MVC class holds an instance - the singleton of the router.

It also makes it easy to access the current state (e.g., the current base, locale, and page).

Last but not least, it is designed to work with bases and pages - i.e. to retrieve instances of specific bases and pages.

Method Meaning of
public static getRouter(
): MVC_Router_Interface
Returns a singleton instance of the router.

If it hasn't been created yet, it creates it using factory.
public static setRouter(
MVC_Router_Interface $router
): void
It is possible to impose your own instance of router.
public static getBase(
?string $base_id=null
): MVC_Base_Interface|null
Returns an instance of the base.

If no ID is specified, then returns an instance of the current base as identified by the router.
public static getBases(
): MVC_Base_Interface[]
Returns instances of all defined bases.
public static getDefaultBase(
): MVC_Base_Interface|null
Returns the instance of base that is marked as the default.
public static getLocale(
): Locale|null
Returns an instance of the current locale.

This is a shortcut for calling: MVC::getRouter()->getLocale(); Stays using: MVC::getLocale();
public static getPage(
string|null $page_id=null,
Locale|null $locale = null,
string|null $base_id = null
): MVC_Page_Interface|null
Returns an instance of page. All parameters are optional, and the default parameter values are the current values (current page, current locale, and current base).

This way you get a certain page in the current locale of the current base: $page MVC::getPage('page_id');
Of course, if you want to, for example, page with the same ID as the current one, but in a different locale, you can do this: $page MVC::getPagelocale$locale );
If you want an instance of the current page, then you can do this: $page MVC::getPage();
public static getHomePage(
Locale|null $locale = null,
string|null $base_id = null
): MVC_Page_Interface|null
Returns an instance of the root page specified by base and locale. All parameters are optional, and the default parameter values are the current values (current locale and current base).

For example, if you want a homepage, but in a different locale than the current one, you can do this: $page MVC::getHomepagePagelocale$locale );
If you want an instance of the current homepage, then you can do this: $page MVC::getHomePage();
public static getPages(
string $base_id,
Locale $locale
): MVC_Page_Interface[]
Returns an array of instances of all pages of a given base and locale.
Previous chapter
Jet\MVC_Router
Next chapter
View - Jet\MVC_View