Useful functionalities.

Gain much time with those built-in functions.

All theses built-in functionalities are available as you include the Page class, present in Components/Page.class.php.

So, all the functions can be called using anywhere on your pages : $Page->name_of_the_function();.

(returned type)
(void)

$Page->setTitle(string $title [, bool $config_title]);

Set the title of your current page. Use it in the controller.

If $config_title is set to true, setTitle() returns the $title concatenated with the website_title, present in the Components/config.json config file.

Then, call $Page->getTitle(); in your view to get it.

[ Notifications system ]

Three functions, easy to use, easy to custom.

(void)

$Page->addInfo(string $title, string $message);

Breakings! An incredible framework!

$Page->addError(string $title, string $message);

Wow! It's dangerous here!
  • $title = the title (shown in bold).
  • $message = the message (shown as a paragraph below the title).

$Page->showInfos([bool $remove_notifs=true]);

Only shows infos, and removes them if $remove_notifs is not false.

$Page->showErrors([bool $remove_notifs=true]);

Only shows errors, and removes them if $remove_notifs is not false.

$Page->showNotifications([bool $remove_notifs=true]);

Shows both errors and infos, and removes them if $remove_notifs is not false.


You can cumulate the notifications :

$Page->addError("Title 1", "Blablabla");
$Page->addError("Title 2", "Blobloblo");
$Page->showNotifications();
                    

Will output :

Title 1 Blablabla
Title 2 Blobloblo

You can edit the styles in Components/assets/css/app.css.

[ Log system ]

One function, powerful options.

$Page->addToLog(string $content[,string $title [,array $options]]);

  • $content : the description of the event.
  • $title : the title of the event.
  • $options : classic/associative array.

Add a log line. Logs are stored under Components/log/x.log.json (x starts at 0). Here is an example of how one entry looks like :

    Using:
    ------
    $Page->addToLog("User trying to access a non-authorized ressource.",
                    "User denied !",
                    array("ip", "custom_data" => "Blabla", "custom_data_empty")
                   );

    Creates :
    ------
    [{
        "title": "User denied !",
        "options": [
                        {
                            "f_name": "ip",
                            "content": "84.xxx.xxx.xxx"
                        },
                        {
                            "f_name": "my_custom_data",
                            "content": "Blabla"
                        },
                        {
                            "f_name": "custom_data_empty",
                            "content": ""
                        }
                    ],
        "content": "User trying to access a non-authorized ressource.",
        "date": "18:33 26\/07\/2017",
        "timestamp": 1501086799
    }]
                    

As you can see, the "ip" option automatically attributes the IP of the client as its content. Here are the available option names that auto-fill with corresponding data :

  • "ip" : IP of the user.
  • "backtrace" : File from where is called addToLog().

You can specify a max file size for one log file by attributing to the "log_max_file_size" option, a max value in octet (4096 by default), in the Components/config.json file.
If the current log file exceeds that value, a new one will be create and logs will be written in.

You can deactivate the log system by putting "yes" in the "log_disable" option in the Components/config.json file.

[ $_POST variables functions ]

(bool)

$Page->is_post(array $post_parameters_to_check);

Replaces the isset($_POST["parameter_name"]) function. Example :

Before:
if(isset($_POST["input_1"])&&isset($_POST["input_2"])&&isset($_POST["input_3"])[...]){true}

Now:
if($Page->is_post(array("input_1","input_2","input_3",[...]))){true}
                    
(bool)

$Page->is_post_not_empty(array $post_parameters_to_check);

Replaces the isset($_POST["parameter_name"])&&!empty($_POST["parameter_name"]) functions. Example :

Before:
if(isset($_POST["input_1"])&&!empty($_POST["input_1"])&&isset($_POST["input_2"])&&!empty($_POST["input_2"])[...]){true}

Now:
if($Page->is_post_not_empty(array("input_1","input_2",[...]))){true}
                    
(void)

$Page->post_variables_init(array $post_params_to_declare);

This function declares the $_POST variables declared in the array. Pretty useful when you have to deal with many post parameters.

Before :
$input_1=$_POST["input_1"];
$input_2=$_POST["input_2"];
[...]

Now :
$Page->post_variables_init(array("input_1","input_2",[...])); // POST parameters are declared with their name as variable.
var_dump($input_1); // Will output the value of $_POST["input_1"]
var_dump($input_2); // Will output the value of $_POST["input_2"]

                    

[ Others ]

A lot of small but useful functions.

(string)

$Page->getIp();

Returns the IP address of the user.

(undefined)

$Page->moreFunctionsSoon();

=)