Kframe PHP MVC framework. A basic mvc pattern framework, most functions name are same like Laravel (inspired by Laravel) I want to improve it with github community, please contribute and make it strong as much as possible. Any contribution will be appreciated.
Kframe uses Composer to Manage Dependencies and You need to have Composer installed on your machine to continue If you don't already have composer, Download it here: http://getcomposer.org/
After Installing Composer, Run command
composer install
- Set database detail in .env file, then run migration command to create default users table.
- Define specific table for users authentication in .env "AUTH_TABLE" environment constant. like "AUTH_TABLE=users"
Set Environment variable "APP_ENV" in .env as development or production to show or hide errors, set by default is development.
We can set go back url for 404 error page for production mode in config\app.php. Example:
$go_back = url();
We can define routes in route/route.php file as below.
Route::get('/', [App\Controllers\HomeController::class, 'index']);
Group route to set prefix and namespace
Route::group(['prefix'=>'admin','namespace'=>'Admin'], function () {
Route::get('dashboard', [App\Controllers\HomeController::class, 'index']);
});
Create middleware in App\Middleware directory, define rules in middleware handler function then register it in App\Kernel.php.
Example:
public $routeMiddleware = [
'auth' => Authenticate::class,
];
Then Any Controllers's constructor you can call middleware.
Example:
$this->middleware('auth');
For more than one middleware.
$this->middleware(['auth','web']);
There are some nice Facades like
Captcha: There is available a Captcha Facade, so we can use this to render and verify captcha (helpers also available for this).
Toastr: There is a Facade for alert message in toastr.
Note:(first need to include a helper function called toastr() in html footer page) Then add Toastr Facade in any Controllers where you want to use it and then call its function like:
Toastr::error('message') ,
Toastr::success('message') ,
Toastr::warning('message')
Toastr::info('message')
Mail Facade:
e.g:
Mail::send('mail', [], function($mail) {
$mail->to('[email protected]', 'Kframe');
$mail->subject('HTML Testing Mail');
$mail->from('[email protected]','Kframe');
$mail->attachment('path','Kframe');
});
There are two type bootstrap base pagination provided by framework. You can call on query builder as well as on model.
-
paginate()
-
simplePaginate();
Example:
DB::table('users')->paginate(10);
Or
$this->model('Users')->paginate(10);
Then include below snippet to render the pagination on view page like:
<?php echo $render->links?>
There is a csrf token verification helper called csrf_toke() provided to add in each post form (it will include an input field with csrf token value)
example:
<?php echo csrf_token(); ?>
There are many default helper functions, like
captcha(): to render the captcha in html form directly.
verifyCaptcha(): to verify captcha.
Include index.html in every directory to deny the directory listing.
Also add .htaccess in bootstrap directory to perverting direct access of autoload file
in autoload.php file define a constant called "root_path".
then add a line "define('root_path') OR exit('No direct script access allowed')" in each file at the top
Available commands:
For Auth Scaffolding:
php kframe make:auth auth
Note: above command will create controllers in controllers/Auth, also will create authenticate route in route file. Example:
Route::authenticate();
If you want to disable register route then add ['register'=>false]
Example:
Route::authenticate(['register' => false]);
For create a model:
php kframe make:model model name
For create a Controller:
php kframe make:Controllers Controllers name
Create migration for new table in "migrations/Migration.php" file and then run following command:
php kframe migration migrate
For register custom helpers file in framework, make a directory under app, create a php file in this directory then for register this helper globally in framework include name in 'config/app.php' helpers like:
'helpers' => array('helpers/my_helper'),
For more then one:
'helpers' => array('helpers/my_helper','helpers/my_other_helper'),
For register custom library file in framework, make a directory under app, create a php file in this directory then for register this library globally in framework include name in 'config/app.php' libraries like:
'libraries' => array('libraries/my_library'),
For more then one:
'libraries' => array('libraries/my_library','libraries/other_library'),