https://github.com/ghaninia/invites
The best implementation of the Model-View-Controller architectural pattern in PHP!
https://github.com/ghaninia/invites
agent ajax callback composer mini-mvc php redirects routename
Last synced: 8 months ago
JSON representation
The best implementation of the Model-View-Controller architectural pattern in PHP!
- Host: GitHub
- URL: https://github.com/ghaninia/invites
- Owner: ghaninia
- License: mit
- Created: 2018-08-14T04:57:38.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2018-12-06T04:27:09.000Z (almost 7 years ago)
- Last Synced: 2025-01-16T20:57:13.848Z (9 months ago)
- Topics: agent, ajax, callback, composer, mini-mvc, php, redirects, routename
- Language: JavaScript
- Homepage: https://ghaninia.ir
- Size: 570 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Invites is a mini sample mvc freamwork , Open source PHP router , Query Builder , Response , Redirect , ...
USAGE
1 - install Composer
2 - Open the cmd and type in it and then press enter ...
composer install
3 - Pase the core file in your project.
4 - Set namespace In Composer Default namespace is App\Core and ReWrite in Core Files
How to use ROUTE , CONTROLLER ?
Make a file .htaccess on your project home page
Apache
RewriteEngine On
RewriteBase /
# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [QSA,L]
Nginx
rewrite ^/(.*)/$ /$1 redirect;
if (!-e $request_filename){
rewrite ^(.*)$ /index.php break;
}
App\Core\Route ;
Route::get("url" , "Callback OR Controller" , "routename") ;
Route::post("url" , "Callback OR Controller" , "routename") ;
Route::any("url" , "Callback OR Controller" , "routename") ;
Route::get("post/(:any)" , "Callback OR Controller" , "routename") ; // you can use wallcard
Route::get("post/(:num)" , function($id){
echo $id ;
}, "routename") ; // ...
Route::disptach() ;
Demo
//web.php
use App\Core\Route ;
Route::get("/" , "MainController@index" , "mainPage") ;
Route::get("/post/(:num)" , "MainController@post" , "post") ;
//Controller folder
//folder App\Controller
use App\Controller\MainController ;
use App\Core\Controller;
class MainController extends Controller {
public function index(){
return view('main') ; // view folder App\Resource basename withOut ".php"
}
public function post($id)
{
echo $id ;
}
// you can use validateor !
public function index(){
$request = new Request() ;
$this-validate($request , [
'filedName' => [ 'required' , 'mobile' , 'url' , 'persian' , 'ip' , 'email' ] ,
]);
}
// you can youe middleware
public function __construct(){
$this->middleware(
[
"methodName" => ["guard"] ,
"methodName" => ["guest"] ,
]
);
}
}
Route::currentRouteName() ; // The name of the route shows me the current page
Route::currentRouteMethod() ; // The method of the route shows me the current page
abort(404 , 'description') ; // Redirects to page 404 and displays the message
USE Request and Response
1 - use Request,Response Class
Request::input('fieldName' , 'default') ; // return Field Value IF exists otherwise return default
Request::only(['filedNames']) ;
Request::except(['except filedNames']) ;
Request::method() ; //What method is used?
Request::ajax() ; // Is ajax request?
Request::ip() ; // Applicant ip
Request::agent() ; // Applicant user agent
Request::user() ; // If the user login, then show me the information
---
Response::json(['key' => $value , ... ]) ;
Response::download("file link") ;