Shadow MVC Framework v0.1
, (*1)
, (*2)
, (*3)
Installation
Install using composer, (*4)
composer create-project zarna0x/shadow_framework myproject
or you can clone git repository, (*5)
git clone https://github.com/Zarna0x/Shadow-mvc-framework.git
and, (*6)
composer install
Features
ShadowPHP is simple and flexible mvc framework which provides various features just out of the box,
Such as:, (*7)
- Models
- Views
- Controllers
- Custom routes
- Command line tool
- Request handling
- Session handling
- Flash Messages/Sessions
- Input validation
.etc, (*8)
furthermore you can add your own features and libraries, (*9)
console.shadow
You can create models and controllers from your terminal using console.shadow
just type:, (*10)
php console.shadow
, (*11)
This command will generate controller with name GitShadow, (*12)
GitShadow.php:, (*13)
Define Routes
ShadowPHP has advanced routing capabilities and user can define custom routes(Located in sh_http/Routes.php).
You can define route this way:, (*14)
use ShadowApp\Sys\Router as ShadowRouter;
ShadowRouter::define('/home',[
'controller' => 'index',
'method' => 'hello'
]);
ShadowRouter::run();
OR, (*15)
ShadowRouter::define('/register',function(){
echo "This Is Register"
});
Also you can pass variable to view, (*16)
ShadowRouter::define('/somelink',function(){
ShadowApp\Sys\View::run('rame/index',[
'var' => 'just some random text'
]);
});
Requests
Youn can handle http requests using ShadowPHP's Shadowapp\Sys\Requester class:, (*17)
use \Shadowapp\Sys\Requester as Requester;
1) check if request method is post, (*18)
Requester::isPost();
2) check if request method is Get, (*19)
Requester::isGet();
3) get parameters of post request, (*20)
Requester::getPost('name');
4) redirect user, (*21)
Requester::redirect('home');
5) Retrieve All Input Data, (*22)
Requester::all();
Session
Shadowapp\Sys\Session class provides object-oriented wrapper of session data ., (*23)
1) start Session, (*24)
use \Shadowapp\Sys\Session as Session
Session::start('auth', [
'id' => user->id,
'name' => $user->name
]);
2) get session, (*25)
Session::get('auth');
3) destroy session, (*26)
Session::smash();
4) remove session, (*27)
Session::remove('auth');
5) check if specified key is set, (*28)
Session::has('auth');
Flash Messages
Flash Session temporarily stores the messages in session, then messages can be printed in the next request, (*29)
Session::flashShadow('error','Wrong Username Or Password');
Requester::redirect('login');
and, (*30)
if(Shadowapp\Sys\Session::has('error'))
{
Shadowapp\Sys\Session::flashOutput('error');
}
Validation
ShadowPHP has easy and flexible approach to validate your application's incoming requests
just use Shadowapp\Sys\Validator class, (*31)
Create Validator, (*32)
use \Shadowapp\Sys\Validator as Validator;
Validator::run(Requester::all(),[
'name' => [
'required' => true,
'min' => 3,
'max' => 10,
'empty' => false
],
'pass' => [
'requred' => true,
'min' => 3,
'max' => 20,
]
]);
Check if there is any validation error and redirect user with flash session, (*33)
if(Validator::failed())
{
Session::flashShadow('error',Validator::errorMessage());
Requester::redirect('login');
return;
}