Download the PHP package codera21/sf without Composer
On this page you can find all versions of the php package codera21/sf. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package sf
Short Description Simple php framework inspired by codeigniter, laravel, yii
License MIT
Homepage https://github.com/codera21/SimpleFramework
Informations about the package sf
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_namecd project_namerun php -S localhost:8080
Guidelines
- Controller Name must be in
CapitalCaseand must followControllersuffix - Function inside the Controller also must be in
CapitalCaseand must followActionsuffix - Table in Database and it's respective Model Class name must be in pural.
Getting Started
Using the Controller
Inside Application\WebInterfaceyou 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:
Then in the output navigate to <Host>/<ProjectName>/Page/Index or <Host>/<ProjectName>/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 : <host>/<controller>/<action/method>
Parameters
In the same PageController I created a new method AddAction(int $num1 , int $num2) the code is as follows:
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:
Model
Suppose you have a table named items with columns ID , ItemName, ItemPrice, ItemCategory. Then in WebInterface/Models create a class Items like:
Repository
Make a Repo of database functions in Application/Repository make a new class ItemRepo with constructor initialized with Model class ( made above) and table like this:
Calling Common database queries:
In the PageController's IndexAction I can create an object of ItemRepo and use its common queries:
It is a good idea to make object in the constructor if more than one function uses the particular Repository:
list of common queries
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:
Many More Features
There are many more features of SimpleFramework, that is not covered here. please go through this framework and see for yourself :)