https://github.com/codera21/simpleframework
It is a MVC framwork made in PHP, inspired by CodeIgniter
https://github.com/codera21/simpleframework
php php-framework php-library php7
Last synced: 2 months ago
JSON representation
It is a MVC framwork made in PHP, inspired by CodeIgniter
- Host: GitHub
- URL: https://github.com/codera21/simpleframework
- Owner: codera21
- Created: 2018-09-02T12:02:14.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-10-01T13:03:35.000Z (over 4 years ago)
- Last Synced: 2025-03-23T01:41:39.920Z (2 months ago)
- Topics: php, php-framework, php-library, php7
- Language: PHP
- Homepage:
- Size: 564 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# SimpleFramework
It is a MVC framwork made in PHP.## Requirement
Since I am using latest version of twig and it needs at least php 7.0.
you will need what a typical php project will require.
## Installation
run:
- `composer create-project codera21/sf project_name`
- `cd project_name`
- `run php -S localhost:8080`## Guidelines
1. Controller Name must be in `CapitalCase` and must follow `Controller` suffix
2. Function inside the Controller also must be in `CapitalCase` and must follow `Action` suffix
3. Table in Database and it's respective Model Class name must be in pural.## Getting Started
### Using the Controller
Inside `Application\WebInterface`you will see three folders `Controllers` , `Models` , `ViewModels` , `Views`. Goto Controllers then Create one new Controller Let's Say `PageController.php` with one method `IndexAction()` the code is as shown below:
```
//Page/Index` or `//Page` in my case `http://localhost:90/SimpleFrameWork/Page` then you will see the page with string "Hello World" echoed out.
Yes the routes are created automatically in this format : `//`##### Parameters
In the same PageController I created a new method AddAction(int $num1 , int $num2) the code is as follows:
```
public function AddAction($num1, $num2)
{
echo $num1 + $num2;
}
```
Now if you navigate to link like `http://localhost:90/SimpleFrameWork/Page/Add/5/5` then you will see in the page 10 echoed out.### Dealing with database
One of the strong suite of the SimpleFramework is its easy to use out of the box ORM for common database queries:#### Connection to database
Goto `Application/Config/DbConfig.php` and fill up the ServerName, Username, Password and DatabaseName.
eg:
```
function __construct()
{
$this->databaseConnection = new DatabaseConnection();$this->databaseConnection->ServerName = 'localhost';
$this->databaseConnection->Username = 'root';
$this->databaseConnection->Password = '';
$this->databaseConnection->DatabaseName = 'products';
}
```
### Model
Suppose you have a table named items with columns ID , ItemName, ItemPrice, ItemCategory. Then in `WebInterface/Models` create a class `Items` like:
```
table, $this->modelClass);
}
}
```
### Calling Common database queries:
In the PageController's `IndexAction` I can create an object of `ItemRepo` and use its common queries:
```
public function IndexAction()
{
$itemRepo = new ItemRepo();
$itemData = $itemRepo->GetAll();
$this->load->TwigView('Page/index', ['data' => $itemData]);
}
```
It is a good idea to make object in the constructor if more than one function uses the particular Repository:
```
itemRepo = new ItemRepo();
}
public function IndexAction()
{
$itemData = $this->itemRepo->GetAll();
$this->load->TwigView('Page/index', ['data' => $itemData]);
}
}
```#### list of common queries
```
Insert($model, $removeFields = array(), $table = null) // this is protected function
UpdateTable($model, $removeFields, $id = null, $table = null, $updateFrom = null, $updateFromValue = null) // this is also protected
GetCurrentDate()
GetCurrentDateTime()
Delete($id, $idFieldName = null)
GetById($id, $idFieldName = null)
GetAllByViewModelWithOutJoin($viewModelClass, $whereConditions = array())
GetAll()
Check($id)
```
#### custom query ( we use PDO)
you can create your own custom functions and make your own queries like this in `Repository/ItemRepo` new function `Custom` is made:
```
public function Custom($id)
{
$sql = "select * from items where ID = :ID";
$sqlQuery = $this->dbConnection->prepare($sql);
$sqlQuery->bindParam(':ID', $id);
$sqlQuery->execute();
}
```#### Many More Features
There are many more features of SimpleFramework, that is not covered here. please go through this framework and see for yourself :)