Jet\MVC_Page

We have already explained what is base and page and what role they play in Jet MVC.

Now let's take a detailed look at the Jet\MVC_Page class and therefore also at the Jet\MVC_Page_Interface interface.

This class is also instantiated principally by relevant factories.

The Jet\MVC_Page class is one of the largest Jet classes ever. That is why it is divided into parts, i.e. into individual traits. And I will divide the description of this class similarly.

General - trait Jet\MVC_Page_Trait_Main

This trait addresses basic and general matters.

Method Meaning
public getBaseId(
): string
Returns the ID of the base to which the page belongs.
public setBaseId(
string $base_id
): void
Sets the ID of the base to which the page belongs.

This method is intended primarily for tools (e.g. Jet Studio)
public getBase(
): MVC_Base
Returns the base instance to which the page belongs.
public setBase(
MVC_Base $base
): void
Sets the base to which the page belongs.

This method is intended primarily for tools (e.g. Jet Studio)
public getLocale(
): Locale
Returns the locale to which the page belongs.
public setLocale(
Locale $locale
): void
Sets the localization to which the page belongs.

This method is intended primarily for tools (e.g. Jet Studio)
public getId(
): string
Returns the page ID.
public setId(
string $id
): void
Sets the page ID.

This method is intended primarily for tools (e.g. Jet Studio)
public setSourceModuleName(
string $source_module_name
): void
Nastaví název modulu, který stránku definuje (pokud se jedná o stránku definovanou modulem)

Tato metoda je určená primárně pro nástroje (např. Jet Studio)
public getSourceModuleName(
): void
Returns the name of the module that defines the page (if it is a page defined by a module)

This method is intended primarily for tools (e.g. Jet Studio)
public getKey(
): string
Returns the page key.

A key is a text string composed as follows: page_ID:locale_code:base_ID
public getName(
): string
Returns the internal name.

The internal name is for things like Jet Studio, or administration. The
data is not intended to be used for display to the end user (normal visitor).
public setName(
string $name
): void
Sets the internal name. See method getName()
public getIsActive(
): bool
Indicates whether the page is/is not active.

The page has its own flag whether it is active, but this method does not consider only that. First, it uses the getIsDeactivatedByDefault method to see if any parent element happens to be inactive, and if so, the page is automatically inactive. Only if the parent pages are active does the actual page flag become relevant.
public setIsActive(
bool $is_active
): void
Sets the page's custom flag is/is not active.
public getIsDeactivatedByDefault(
): bool
Detects whether any of the parent elements are inactive. Thus true returns if:
  • Is the parental page inactive
  • The relevant localisation is inactive
  • Is the corresponding base inactive
public getTitle(
): string
Returns the page title. The headline is already intended for use, for example, on a website or e-shop - i.e. for end users.
public setTitle(
string $title
): void
Sets the page title.
public getIcon(
): string
The page can peace the assigned icon. How the icon is specifically implemented and displayed is up to you.
I use Font Awesome icons, for example, and that's how the sample app is done, but it may not be the only way by any means. The
important thing is that you can assign the icon data to the page and then use it. It's useful for administration and the like, for example.
public setIcon(
string $icon
): void
Sets the page icon.
public getMenuTitle(
): string
The page can have an extra headline for the menu. If not set, the main headline is used.
public setMenuTitle(
string $menu_title
): void
Sets the page title for the menu.
public getBreadcrumbTitle(
): string
The page can have an extra headline for breadcrumb navigation. If not set, the main headline is used.
public setBreadcrumbTitle(
string $breadcrumb_title
): void
Sets the page title for breadcrumb navigation.
public getSSLRequired(
): bool
Indicates whether the page requires/does not require https connection.

The page has its own flag whether https is required, but again only this flag is not taken into account. First, it uses the isSSLRequiredByDefault method to determine if https happens to be required by any of the parent elements, and if so, the page automatically requires https as well.
public setSSLRequired(
bool $SSL_required
): void
It sets whether the page requires / does not require https connection.

This option is practically useless nowadays. It is definitely better to have the whole base on https. But for the sake of consistency this option is.
public isSSLRequiredByDefault(
): bool
Determines whether https requires any of the parent elements. True returns if:
  • Https requires parent site
  • \li>Https requires appropriate locale
  • Https requires appropriate base
public isCurrent(
): bool
Returns true if the given page instance is the one that is currently current for the request being processed.
public isInCurrentPath(
): bool
I'd rather explain with an example. Suppose the current page is a page with ID page-3.

All page-3 has parents page-1 and page-2.

Then the current path to the open page is: _homepage_ / page-1 / page-2 / page-3

You are working with an instance of page-2.

This means that the method will return true because page-2 is in the current path. Or you could also say that page-2 is one of the parent pages of the current page.
public setDataFilePath(
string $data_file_path
): void
Sets the path to the file where the page definition is stored.

The value is set automatically by Jet during initialization.
public getDataFilePath(
bool $actualized=false
): string
Returns the path to the file where the page definition is stored.

If $actualized = true, it returns the path updated according to the current form of the definition. That is, a path that will reflect any changes to the page's URL and therefore its directory.
public getDataDirPath(
bool $actualized=false
): string
Returns the path to the directory where the page definition is stored.

If $actualized = true, it returns the path updated according to the current form of the definition. That is, a path that will reflect any changes to the page's URL and thus its directory.

Initialization - trait Jet\MVC_Page_Trait_Initialization

This trait handles everything around initializing the page list. Or perhaps better said, uploading them and compiling all the necessary data.

Method Meaning of
public static createByData(
MVC_Base_Interface $base,
Locale $locale,
array $data
): static
Creates a page instance based on the data in the array. It is mainly used for internal and tooling purposes. It is not commonly used in the application space.
public static getRelativePathMap(
MVC_Base $base,
Locale $locale
): array
Another method especially for internal purposes. Returns a map of relative paths (parts of URLs) of pages of a given localization of a given base. This method (and thus the map) is used by router.
public static loadMaps(
MVC_Base $base,
Locale $locale
): array
For internal purposes. Includes internal maps that the system needs to work with pages.
public __wakeup(
) : void
Magic method that sets the deserialized page instance (especially after loading from cache). 

Tree structure - trait Jet\MVC_Page_Trait_Tree

This trait addresses the interrelationships of pages that are organized into a tree structure.

Method Meaning of
public setParentId(
string $page_id
) : void
Sets the ID of the parent page.

This method is again primarily intended for tools like Jet Studio.
public getParent(
): static|null
Returns an instance of the parent page. The root page (i.e. homepage) will of course return null.
public getOrder(
): int
Returns the order (or you could say priority) of the page. This can be used, for example, to sort different menus and so on.
public setOrder(
int $order
): void    
Sets the page order/priority.
public getPath(
): array
Returns the path to the page from the root page in the form of an array containing the parent page ID.
public getChildren(
): MVC_Page[]
Returns the child pages as an array containing their instances. Returns only descendants from the next level. Not the descendants of the descendants.
public getChildrenKeys(
): array
Returns the keys of the descendants of the page (key: see the getKey() method) and only from the next level (not from other levels, i.e. descendants of descendants).
public getChildrenIds(
): array
Returns the descendant ID of the page and only from the next level.

URL - trait Jet\MVC_Page_Trait_URL

As the name suggests, trait solves everything around the URL of the site.

Metoda Význam
public getURL(
array $path_fragments = [],
array $GET_params = []
): string
Returns the full URL of the page to match the definition. So if the page requires https, then it will return the URL with https and vice versa.

The parameters of the method are important. Let's take a look at them:

$path_fragments:
Suppose you want the URL of a page whose URL is https://domain/page/ by definition, but that's not enough.

For example, this is a page of a product catalog and you need the URL of a product. So this:
https://domain/page/category/product/ 

Quite a common situation. Moreover, each part of the URL should be encoded accordingly and a string must be constructed ...
How to do it? Like this: MVC:getPage($id)->getURL(path_fragments: [$catalog_url$procut_url]) And Jet takes care of the rest, you don't have to do it by hand.

$GET_params:
And what if we want some GET parameters in the URL? No problem, of course: MVC::getPage($id)->getURL(GET_params:['param'=>$value'param2'=>$value2])
public getURLPath(
array $path_fragments = [],
array $GET_params = []
): string
It works the same as getURL, but it does not return the full URL, but only the URL without the schema and domain - the path.

For example, instead of: https://domain/page/

it returns only: /page/

The parameters work identically to the getURL method
public getNonSchemaURL(
array $path_fragments = [],
array $GET_params = []
): string
It works the same as getURL, but it does not return the whole URL, but only the URL without the schema.

For example, instead of: https://domain/page/

it returns only: //domain/page/

Parameters work identically to the getURL method
public getNonSslURL(
array $path_fragments = [],
array $GET_params = []
): string
It works the same as getURL, but regardless of the definition, it returns a URL with http

The parameters work identically to the getURL method
public getSslURL(
array $path_fragments = [],
array $GET_params = []
): string
It works the same as getURL, but regardless of the definition, it returns a URL with https

The parameters work identically to the getURL method
public setRelativePathFragment(
string $relative_path_fragment
): void
Sets the part of the URL that applies to the page.

It is used for tools like Jet Studio.
public getRelativePathFragment(
): string
Returns the part of the URL that is relevant to the page.

It is used for tools like Jet Studio.
public getRelativePath(
): string
Returns the part of the URL that is the relative path. Let's use an example to illustrate.

The base and localization has a root URL of http://domain/cs/
The page has a full URL of ttp://domain/cs/about-us/contact/

The relative path is therefore about-us/contact/
public setRelativePath(
string $relative_path
): void
Sets the relative path.

Serves for tools like Jet Studio.

Authentication and authorization - trait Jet\MVC_Page_Trait_Auth

Trait addresses issues around non-public sites. That is, those where the user/visitor must be logged in and have the necessary permissions.

Method Meaning of
public getIsSecret(
): bool
Indicates whether the page is/is not secret. That is, whether it requires the user to log in and verify his rights.

The page has its own flag whether it is secret, but again, only this flag is not taken into account. First, it uses the isSecretByDefault method to determine if any of the parent elements are secret, and if so, the page is automatically secret - regardless of its own settings (the flag can be false and it is still secret).
public setIsSecret(
bool $is_secret
): void
Sets whether the page is/is not secret.
public isSecretByDefault(
): bool
It determines whether any of the parent elements are secret. That is, either the parent page or the entire base. If so, the method returns true and the page is automatically secret.
public authorize(
): bool
He calls this method router.

If the page is accessible in terms of permission checking, it returns true, otherwise false.

The page is accessible when:
  • Not a secret
  • It is secret, but the user is logged in and also has the necessary permissions to visit the site
public accessAllowed(
): bool
This method is intended for general use - i.e. especially in the application space.

Classic situation: you have a page and it is possible that it may not be accessible to the user and you want to display the link to it only when it is accessible. Here's how you do it: $page MVC::getPage($id);
if(
$page->accessAllowed()) {
     echo 
$page->getURL();
}

Layout - trait Jet\MVC_Page_Trait_Layout

It is clear from the name that this is all about layout, i.e. Jet\MVC_Layout.

Method Meaning of
public getLayoutScriptName(
): string
Returns the name of the layout script set for the page.
public setLayoutScriptName(
string $layout_script_name
): void
Sets the name of the layout script for the page.

Although primarily intended for Jet Studio and similar tools, I have used this method in the application space.
public getLayoutsPath(
): string
Returns the path to the directory where the layouts are. In practice, this is equivalent to calling $page->getBase()->getLayoutsPath();
public initializeLayout(
): void
The method initializes the layout according to the page definition. It is called when the output is rendered.

Meta tagy - trait Jet\MVC_Page_Trait_MetaTags

And this trait handles everything around meta tags for HTML page headers.

Method Meaning of
public getMetaTags(
): MVC_Page_MetaTag[]
Returns the default page meta tags. And beware, it returns all the meta tags that belong to the page. This includes those defined within the base. If the base and the page itself define the same meta tag (with the same attribute), the parent is the one defined by the page itself.

This is the method used to generate the output.
public setMetaTag(
string $attribute,
string $attribute_value,
string $content
) : void
Sets the meta tag of the page. If a similar meta tag has not been defined yet, it will add it. Otherwise, it sets the content value of an already defined meta tag (even if it was a base-defined meta tag and not a page-defined meta tag)

This method is useful for the application space. For example, when you want to set description and keywords according to the current article or product (if you are developing an e-shop for example)
public setMetaTags(
MVC_Page_MetaTag[] $meta_tags
): void
Bulk sets the definition of meta tags page. It does not affect tags defined by the base, but only those defined by the page itself.
public addMetaTag(
MVC_Page_MetaTag $meta_tag
): void
Adds a meta tag to the page definition.

Http hlavičky - trait Jet\MVC_Page_Trait_HttpHeaders

This may be a little specific. The page can define http headers in addition to everything else that will be returned in the response. And what good is that? For example, you have a fully static page, no operation is needed to display it - so you don't have the ability to send headers using some application logic. But you still need to specify for some reason what http headers will be sent in the response. And maybe you can think of other uses.

Method Meaning of
public getHttpHeaders(
): array
Returns the defined http headers. Warning! Includes headers defined by any of the parent sites.

A simple associated array is returned, where the key is the http header name and the value of the array element is also the header value.
public setHttpHeaders
array $http_headers 
): void
Sets http headers to the definition of the page (not to parent pages).

Again, the header definition is simple - an associated field where the key is the name and the value is simply the header value.

Internal parameters - trait Jet\MVC_Page_Trait_Parameters

These are parameters and their values that can be freely selected by you. All usable by your application. Thus, you have the possibility to simply define what is not yet defined for the pages.

Example? Let's say you automatically generate navigation and various menus. But how to determine which page will be in the main page and which will not? You can use internal parameters to define your own flags for pages. And certainly for many other things.

Method Meaning of
public getParameters(
): array
Returns a list of internal parameters in a similarly associated array, where the key is the name of the parameter.

Unlike meta tags and http headers, internal parameters are always related only to a specific page. Thus, they never return the parameters of the parent page and so on. 
public setParameters(
array $parameters
): void
Sets the parameters for the page in bulk. The parameters are again in the form of an associated field.
public setParameter
string $key, 
mixed $value 
): void
Sets one parameter.
public getParameter(
string $key,
mixed $default_value = null
): mixed
Returns the value of the specified parameter. If the parameter does not exist, then it returns the default value.
public parameterExists(
string $key
): bool
Determines whether the parameter exists.

Table of Contents - trait Jet\MVC_Page_Trait_Content

And now the content of the page, which is quite a crucial thing.

Static page or page generated by callback

Method Meaning of
public setOutput(
string|callable $output
): void
As you read here there are several ways the page defines what its output will be.
And this method sets the output in the situation:
  • When the page is fully static. So it just sends some HTML output and that's it.
  • When the page will be generated by some function/method.
public getOutput(
): string|callable|null
Returns the set page output. See method setOutput()

Defined set of content

Method Meaning of
public getContent(
): MVC_Page_Content[]
Returns the definition of the content of the page.

Of course there is no inheritance (as in the case of meta tags and http headers). Each page has its own definition.
public setContent(
MVC_Page_Content[] $contents
): void
Bulk sets the content definition. 
public addContent(
MVC_Page_Content $content
): void
Adds one content definition.
public removeContent(
int $index
): void
Removes the content definition at the given position, where 0 = first position. 

Cache - trait Jet\MVC_Page_Trait_Cache

The MVC cache is a separate topic. But I will at least briefly explain the meaning of the following methods as they relate to the context of the cache.

What is the context of a cache? A cache entry must be identified somehow. The base ID, the localization code, the page ID, then a key identifying the specific content (i.e., a specific module, controller, etc.) are used for this identification.

But in practice this may not be enough. For example, this page you are reading is still the same page from an MVC perspective for all the documentation chapters that the Web.Doc.Browser module just displayed this article on. Even if you click to a different chapter, it will always be the same base, the same page, and the same module for MVC.

Thus, the data from Jet MVC is no longer enough to identify the records in the cache. You need to add additional resolution. In this particular case you are looking at right now, that resolution is the documentation article ID. It is the specific context that you have the open documentation article/chapter.

What will constitute the context in your application? That is, if you need any context at all for a given situation ... Those are questions for you, it's about how you design the project. What the context will be is not fixed.

Method Meaning of
public setCacheContext
string $cache_context 
): void
Sets the cache context.

Method for application space.
public getCacheContext(
): string
Returns the set context.

Handlery - trait Jet\MVC_Page_Trait_Handlers

Trait is almost at the end of this chapter of the documentation, but it is all the more interesting. Here are the methods in charge of processing and displaying the page.

Method Meaning of
public resolve(
): bool
This method is called by the router at the end of the request recognition process. So the router already knows everything it needs to know, but the page has the last word. What it does is to request all its content - the individual module controllers and their resolve methods - to resolve the situation. If any of the modules need to do any more discovery, it does it here. But let's take a concrete example.

As you know from this chapter, there may be an unprocessed part of the URL (that doesn't belong to the page). That part of the URL may be the URL of an article, for example.

You are looking at such a thing.
The URL of this page is: https://www.php-jet.net/doc/en/doc/mvc-in-general/jet-mvc/page/jet-mvc-page
The unprocessed part of the URL of this page is "en/doc/mvc-in-general/jet-mvc/page/jet-mvc-page".

And this is where the "what to do" question gets resolved. During this process, the Web.Doc.Browser module will process this information and determine that it's OK and it's the URL of the article you're reading right now.
This part of the processing process (i.e. the resolve method and its operation) is designed for such operations.

If resolve returns true, the router knows that everything is fine and ready to go and can proceed.

But resolve can also return false, in which case the router knows that something is wrong and the URL being processed is not valid. The result is a 404.
 public handleHttpHeaders(
): void
This method effectively sends the defined http headers as a response. It is therefore already part of the response.
public render(
): string
This method compiles the page output.

Warning! The output (compiled page) is not ined to the user, but returned as a return value!

It is possible to generate the page output as you need and use it as you need. It is also possible to build the page independently - even without the whole request processing process.

But of course the primary purpose of this method is to send the output to the user.

Storage - trait Jet\MVC_Page_Trait_Save

And the last, but not unimportant, trait. Here are the methods for storing page definitions.

Method Meaning of
public toArray(
): array
Similarly to all other entities, the page has a method for converting objects into an associated array (i.e. raw data), which is then intended to be stored.
public saveDataFile(
): void
Saves the page definition data file.
Previous chapter
Page
Next chapter
Content / Jet\MVC_Page_Content