baiseiit / baiseiit
The Baiseiit framework
Installs: 136
Dependents: 0
Suggesters: 0
Security: 0
Stars: 19
Watchers: 2
Forks: 2
Open Issues: 0
Type:project
Requires
- php: ^7.0.10|^8.0
- gabordemooij/redbean: ^5.6
- smarty/smarty: ^3.1
This package is auto-updated.
Last update: 2024-04-27 17:26:35 UTC
README
Baiseiit is a PHP framework based on mvc. Baiseiit contains many useful features and helps web developers create applications faster. Unlike other frameworks, you can directly change the framework code without losing it. Source code in the framework directory.
The minimum PHP version must be 7.0.10
Install
-
Install Composer (https://getcomposer.org)
-
Install the package via composer:
composer create-project --prefer-dist baiseiit/baiseiit blog
Open config/app.php file and establish a database connection. DB_CONNECTION only supports MySQL and Postgresql.
define('DB_CONNECTION', 'mysql'); define('DB_HOST', '127.0.0.1'); define('DB_USER', 'root'); define('DB_PASS', ''); define('DB_NAME', 'baiseiit');
Connecting a database to PostgreSQL:
define('DB_CONNECTION', 'pgsql');
Start the server
Run the command on the command line in the project's base folder
php artisan run
Documentation
Artisan
Artisan provides many useful commands and speeds up development time.
Run the command on the command line in the project's base folder
php artisan help
Route
There are two types of routing: web (routes/web.php) and api (routes/api.php). Use the web if your app doesn't have the integration API, otherwise use the api.
Web
Route::get('/', function($request) { (new HomeController)->example($request); })
Api
Route::get('/', function($request) { Response::json([ 'success' => true ], 200); });
Supported Http methods
Route::get('/', function($request) {}); Route::post('/', function($request) {}); Route::put('/', function($request) {}); Route::delete('/', function($request) {}); Route::patch('/', function($request) {});
Dynamic url
To get a dynamic url resource, we use $request->query[$name]. For example, we need to get a specific user.
- @ specifies that this is a dynamic resource
- $request->query['id'] returns the value @id
Route::get('/users/@id', function($request) { Response::json([ 'id' => $request->query['id'] ], 200); });
Controller
Creates a controller in the app/Controllers directory
php artisan create Controller HomeController
Sets the variable to view
$this->view->set('title', 'Baiseiit');
Return view
$this->view->render('home');
Model
Creates a model in the app/Models directory
php artisan create Model User
Set table
class User extends Model { const TABLE = 'users'; }
View
Creates a view in the client/Views directory
php artisan create View home
We use the Smarty template for views. See the Smarty documentation (https://www.smarty.net/documentation)
<h1>{$title}</h1>
ORM
We use the RedBean ORM. See the RedBean documentation (http://www.redbeanphp.com/api/classes/RedBeanPHP.R.html)
We replaced the Redbean R class with Db
use App\Models\User; class HomeController extends Controller { public function example($request) { $users = Db::findAll(User::TABLE); $this->view->set('users', $users); $this->view->render('home'); } }
Middleware
Creates a middleware in the app/Middleware directory
php artisan create Middleware TestMiddleware
The handle method automatically calls.
class TestMiddleware extends Middleware { public static function handle($request, \Closure $next) { $id = $request->params['id']; if ($id > 10) { return self::redirect('home', [ 'title' => '404 error' ]); } else { return $next($request); } } }
If the check fails you can redirect to error view.
return self::redirect($view, [$params]);
If everything is OK, you must return $next($request);
return $next($request);
Then register the middleware to route:
Route::get('/', function($request) { (new HomeController)->example($request); })->middleware(TestMiddleware::class);
CORS
To configure cors go to the folder config/cors.php.
define('ALLOW_ORIGIN', '*'); define('ALLOW_METHODS', '*'); define('ALLOW_HEADERS', '*'); define('MAX_AGE', 3600);
Storage
You can save all files in the storage folder. The command below returns the path to store the file:
Filesystem::storage('/')
You can create a symbolic link of the Storage.
If you are using Windows run this command as an administrator
php artisan storage link
The storage shortcut is created in the client/assets directory.
Assets
You can get the client/assets file using the following command:
Filesystem::assets('/')
Deployment
You must add the project to the www-data group, and then set the permission to the framework/src/CompiledViews directory.
sudo chown -R www-data:www-data blog sudo chmod -R 777 framework/src/CompiledViews
Nginx configuration
server { listen 80; listen [::]:80; root /var/www/example; index index.php; server_name example.com; location / { try_files $uri $uri/ /index.php?$query_string; } location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php7.4-fpm.sock; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } location ~ /\.ht { deny all; } }