Official documentation of the Pickle framework / For version 1.0
Pickle is a php framework made for modern web development. It is equiped with a solid user system through the entire script. It has an MVC architecture and a lot of methods made for a simple start for all of your projects.
The technologies you have to get or to have in order to use this framework :
You can use the command line if git is installed on your computer. Just run this code in the command interpreter : git clone https://github.com/Antoine-Bergerault/Pickle-framework.git
The file config.php located in the core/Tools directory is the configuration for the database (MySQL). You need to run the file(s) located in the sql folder in order to make the system work.
<?php namespace Pickle\Tools; class Config{ static $host = "localhost";//host name static $username = "root";//username static $password = "";//password static $database = "pickle";//name of the database static $CacheDirectory = "/temp";//the directory where the cache will be stored static $env = 'DEV';//DEV or PROD static $devmail = null; } ?>
You need to run the file(s) located in the src/sql folder in order to make the system work.
The routes have to be specified in the file core/Router/web.php file of your application.
Basically, this file implements new routes, created by the Router object. The declaration of a route looks like that :
Router::method(path, function);
For example :
Router::get('/home', function(){ return 'Welcome !'; }); Router::post('/post', function(){ return view('posts/post'); });
You can also use a controller to manage the request
Router::get('/home', 'MainController@home');
As said in the introduction, Pickle comes with a rich user management system. You can control access to pages within this file.
For example, you can restric a route to only connected users :
Router::get('/profile', ['view' => 'user/profile'])->only_if(App::is_connected());
This method takes a boolean as first argument, and an extra callback function as second argument, if the first is not equal to true. The complete list of user management methods provided by the App object :
All the views have to be created in the Views directory. It is a simple php file containing html elements. You can use the integrated functions to interact with other files, use the App class in order to personalize the page depending on the user data and you can use all the php functions, loops...
To display a view, you can use the view() function :
view('name of the view');
You can do that by using the fillTemplate integrated function
fillTemplate(name, params)
The templates are located in Templates.
This is the same principle as the views. You can use variables injected during the filling. An example :
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <?php loadCSS('default') ?> <?php if(isset($styles)) loadTemplateStyles($styles); ?> <title> <?= $title ?? 'Title' ?> </title> </head> <body> <?php view('components/header') ?> <?=$content?> <?php view('components/footer') ?> <?php if (isset($scripts)) loadTemplateScripts($scripts); ?> </body> </html>
Some functions are integrated in all of the framework. They are create in the core/Tools/function.php files. You can add or delete functions as you want
There is the list of included functions :
This function is just a var_dump function with html pre tags around it
This function makes a javascript redirection with to the path argument
Render the view with the first argument name. If it is in a folder, use the / in the filename. The second argument is for asserting data using the compact php function
Return the absolute url of a given path. If not given, it uses the default path of the router
It returns the website root
It returns the absolute path of the route with the name provided
Print a javascript alert box
It returns a jquery code for executing an ajax get request to the given url
It loads the css file whose the name is provided
It loads the css file whose the name is provided
It returns the natural format of a delay between the current time and the date given. ex : 5 minutes ago
It returns a token whose the length is provided
It runs an ob_get_clean and an ob_start if the current environnement is not set to 'DEV'
It loads the template with the provided name, the current variables and some extra variables if the second parameter is provided
It loads the template with the provided name and add some extra variables if a second parameter is passed
It executes the function loadCSS but you can pass either an array or a name
It executes the function loadJS but you can pass either an array or a name
It returns a date format string with the 'jS F Y' format with de date given
The controllers are located in src/Controllers. The controllers are made to perform php scripts and to use models in order to render the correct view with the correct data. A Controller looks like that :
<?php namespace Pickle; class ExampleController { //You can add methods here public function test(){ $UserModel = new UserModel(); $user = $UserModel->first()->where(['email' => '= ?'])->args(['test@example.com'])->run(); $user = $user[0]; return view('test', compact('user')); } } ?>
It must be save as ExampleController.php
The models are used to perform database queries. The models are located in src/Models.
You need to load the model first :
$UserModel = new UserModel();
You don't need any require.
Then you can perform requests. This are different methods for performing requests :
Select the list of column. ex : $UserModel->select(['id', 'name']);
Get the first element
Get n results. Begining from the second parameter (0 by default)
Adding a where statement which corresponds to the conditions given in the argument. For a safe query, you will need to use the args() method with it. ex : $UserModel->where(['name' = 'LIKE "?%"']);
Pass a list of values for a safe query. Works with the where method. ex : $UserModel->where(['name' => 'LIKE "?%"'])->args(['Ant']);
Order the results by desc by the given param.
Order the results by asc by the given param.
Create a new element into the table (by default the table of the model, but it can be changed using the second parameter). If the third argument is set to true (it is by default), the 'pass' corresponding value is automatically hashed (using PASSWORD_BCRYPT). ex : $UserModel->create(['firstname' => 'John', 'lastname' => 'Doe', 'pass' => 'eb7v2SU83']);
Reset all the settings (except the table name).
Get the sql query.
Performs a query.
Don't forget to use the run() method at the end in order to get the results (you don't need that for the create method).
$UserModel = new $UserModel(); $UserModel->find(10)->select(['name', 'email'])->where(['name' => 'LIKE ?%'])->args(['Jo']); $users = $UserModel->run();
First you have to choose the tablename of your new model.
Then create a file in src/Models like that :
TableModel.php
While "Table" is the name of the table in the database (singular not plurial).
Then fill in the file like this :
<?php namespace Pickle; //import the model reference require_once 'default/Model.php'; class TableModel extends Model{//replace "Table" by the name of your table (singular) //defined the table name for this model public $table = 'table';//replace 'table' by the name of your table (plurial) /* * Create some methods here if you need it */ } ?>
And your model is operational
The middlewares are located in src/Middlewares. There are used to inject script which are common to several pages. For example, the CsrfMiddleware is used for pages which contains form(s). A middleware looks like that :
<?php class ExampleMiddleware { /* * The methods you want */ }
It has to be saved as ExampleMiddleware.php
The methods can be whatever you want.
They are two different methods to use the middlewares :
Just go to public/index.php and edit/create this line :
App::activeMiddlewares(['example']);
If you want to use multiple middlewares you can fill the array.
Do this like this :
App::middleware('example');
There is some middlewares integrated by default in the framework
A middleware made to integrate csrf inputs into your forms and to verify your forms when they are submitted. It is a tool made to strengthen the security of your forms.
All is in the name. A middleware that deletes all the routes if you are not connected instead of the login route(s), and redirect the user to a specific route to get connected.
A really simple middleware that can return a pdf to the browser by settings all the headers needed. The path of the file from the data directory is given as a parameter (without the extension .pdf).
A middleware that can delete the script tags from an html code, and that can convert a string to an html code.
The Pickle framework offers you a way to reload your pages using javascript in order to relaunch the php script.
On pages with this system activated, you can generate your pages using javascript. It offers you the opportunity to defer your entire php script, and to reload it multiple time in order to maintain data up to date. It is accessible from html element with the "data" class.
Print the content of the variable whose the name is given.
Print the property of the object whose the name is given.
Iterate over an array. Works on different depth levels.
Name:
Name
Email:
Use a condition with a boolean variable.
Explore an object. Used to print properties without redefinding data-key.
name..
Execute a function with the data given and print the result of this function.
Execute a function using the element as an argument.
text
The Pickle framework offers you a way to reload your pages using javascript in order to relaunch the php script.
On pages with this system activated, you can generate your pages using javascript. It offers you the opportunity to defer your entire php script, and to reload it multiple time in order to maintain data up to date. It is accessible from html element with the "data" class.
Print the content of the variable whose the name is given.
Print the property of the object whose the name is given.
Iterate over an array. Works on different depth levels.
Name:
Name
Email:
Use a condition with a boolean variable.
Explore an object. Used to print properties without redefinding data-key.
name..
Execute a function with the data given and print the result of this function.
Execute a function using the element as an argument.
text