#1323
Answered
10/23/23, 3:32 PM
Vip15
Answers: 2

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)

#3
10/23/23, 4:02 PM
PHPJetTeam
4

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 
setMyPropertystring $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

#4
10/23/23, 4:06 PM
Vip15
0

Amazing! Thanks!

Your Answer
Privacy Policy