New page properties?
Hi! Jet MVC is really interesting, but I need to add some properties to page entity for my projet. How to do it?
Thanks!
Answers (2)
Hello!
It is possible and it is really simple ;-) In general, you have the following two options:
Use page parameters
You can define such parameters by Jet Studio, or manually in the page definition file.
After that you can access such parameters by methods.
For example:
MVC::getPage()->getParameter('my-param', 'default value')
Extend MVC page entity class
You can define your class which will represent MVC page for your app. For example like this:
<?php namespace JetApplication;
use Jet\MVC_Page;
class MyMVCPage extends MVC_Page
{
protected string $my_property = '';
public function getMyProperty(): string
{
return $this->my_property;
}
public function setMyProperty( string $my_property ): void
{
$this->my_property = $my_property;
}
}
You only need to register this class in the factories. This is done with the initialization script application/Init/Factory.php
And that's it. You can now use your properties and methods throughout the application:
/**
* @var MyMVCPage $page
*/
$page = MVC::getPage();
$page->setMyProperty( 'My Value' );
Enjoy!
Have a nice day
Amazing! Thanks!
Please Sign In or Sign Up. It is really simple, and it takes only few seconds. You can use your Google account.