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();
.
$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.
Three functions, easy to use, easy to custom.
$Page->addInfo(string $title, string $message);
$Page->addError(string $title, string $message);
$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 :
You can edit the styles in Components/assets/css/app.css
.
One function, powerful options.
$Page->addToLog(string $content[,string $title [,array $options]]);
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 :
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.
$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}
$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}
$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"]
A lot of small but useful functions.
$Page->getIp();
Returns the IP address of the user.
$Page->moreFunctionsSoon();
=)