Implementation
Config
You must create a configuration folder which will contain the parameters files
You can name them as you want, both the folder & the parameters files
But the index file will have to call these parameters files.
-
By default, I use a folder named config who contains 2 parameters files : dev-params.php & prod-params.php ...
Each parameters file must contain the Global Constants for Access, Database, Model, View, Controller, Mail & Recaptcha like this :
define("KEY", "value");
-
Now you can configure your Project Parameters !
Parameters File Example
Index
Don't forget to add autoload & sessions (if you need) to the file beginning...
-
In the index file, you have to add the parameters with a require_once
-
For Development :
require_once '../config/dev-params.php';
-
For Production :
require_once '../config/prod-params.php';
-
Now you can change the filename to switch between dev & prod...
-
Then, create the FrontController object :
$frontController = new Pam\Controller\FrontController();
-
And call the run method on it :
$frontController->run();
-
Now you can reach any controller from an URL of the Project !
Index Example
Model
For the Model naming, you need to use the same name than each table...
You can choose, the Model path & the Model suffix, in the parameters.
For example (without any changes to the Model constants), if you have a table named Pizza, you should have a Model named PizzaModel.php
-
To use the Pam CRUD model, simply add this use to each of your models :
use Pam\Model\MainModel;
-
Then you can extends the class to the MainModel :
extends MainModel
-
Now you can access to all CRUD methods of the MainModel !
Simple Model Example
-
If you need a specific query, just create a method to add it :
$query = "SELECT * FROM Table..."
-
Then you should return the query with one of the methods to the PdoDb.php file like this :
return $this->database->getAllData($query);
-
Now you can use both Pam Model methods & personalized Model methods !
Model Example with Personalized Query
View
For the views, Pam use Twig, the Template Engine of Symfony
The only configuration to manage is the 2 View constants in the parameters files
One is for the View template path & the second for the View cache path...
For the Twig functions, filters & tags, please refer to the official documentation
-
Here you can find a Layout example :
Layout View Example -
And here a simple view example :
Simple View Example
Controller
For the Controller naming, you need to use the same name than each access value inside the URL of the website...
You can choose, the Controller path, the Controller default name & the Controller suffix in the parameters.
Same thing for the Contoller Method default name & the Controller Method suffix.
For example (without any changes to the Controller constants), if you watch the URL of this page, the access value is "start", so we have a controller named StartController.php
-
To use the Pam Controller Methods, simply add this use to each of your controllers :
use Pam\Controller\MainController;
-
Then you can extends the class to the MainController :
extends MainController
-
Now you can access to all methods of the Pam Contollers !
Simple Controller Example
-
To get the MainController Methods, simply use "this", then the method :
$this->redirect('home');
-
For Services & SuperGlobales Methods, same thing, but add the getter, for the Class you need, between them :
$this->getPost()->getPostArray();
-
Now you know the 2 kinds of syntax to call all of Pam's Controller methods !
Controller Example with Different Methods Called