nsamsdev / codebasephp
非常基础的PHP VCMM框架
dev-master
2021-03-09 18:32 UTC
Requires
- php: >=7.0.0
- h4cc/wkhtmltopdf-amd64: 0.12.3
- illuminate/database: v5.2.31
- imagine/imagine: v0.6.3
- mikehaertl/phpwkhtmltopdf: 2.2.1
- monolog/monolog: 1.17.2
- nategood/httpful: 0.2.20
- php-ffmpeg/php-ffmpeg: 0.9.2
- phpunit/phpunit: 6.0.9
- sendgrid/sendgrid: 4.0.4
- smarty/smarty: v3.1.29
- sonata-project/cache: 1.0.7
This package is auto-updated.
Last update: 2024-09-10 01:45:29 UTC
README
控制器
<?php use CodeBase\Controller; use CodeBase\HttpRequester; class Home extends Controller { /** a must have contructor on all controller to access parent features */ public function __construct($baseClasses) { parent::__construct($baseClasses, 'Home'); } /** all methods that you wish to have a param passed to via browser url * args must have only one params which is an arrray of all the parameters */ public function index($params) { /** loads \CodeBase\Models\User */ $user = $this->loadModel('User'); } }
路由
/* Routes are defined in app/routes.php, Add method accespts 5 params, 3 mandatory and 2 optional first param is the url route, second param is execution method Class@MethodName, third param is the allowed request method fourth param/optional is boolean, true or false to lock acess to this route based on session set fifth param/optional is the session key name that must be set to access this route if you pass 4th param top the add method you must also pass the 5th param */ <?php /** @file app/routes.php */ use CodeBase\Router; if (!defined('CODEBASE')) { die('Direct Access Not Allowed'); } Router::add('/', 'Home@index', ['GET']); Router::add('account', 'Home@Profile', ['GET'], true, 'userSessionId');
模型(Eloqouent ORM)
<?php namespace CodeBase\Models; class User extends \CodeBase\Model { /** @var array */ protected $fillable = [ 'name', 'age' ]; /** @var bool */ public $timestamps = false; public function addUser($name, $age) { User::create([ 'name' => $name, 'age' => $age ]); } }
模型(标准PDO)
<?php namespace CodeBase\Models; class User extends \CodeBase\BASIC_MODEL { public function __construct() { parent::__construct(); } }
视图
在控制器方法调用内
/** .tpl is automatically added */ $this->view->render('homepage', $dataArrayToPass);
应用程序结构
- app
- controllers
- models
- views
- cache
- compile
- config
- templates
- managers
- routes.php
辅助工具(库)
- 管理器
- PdfCreator
- SessionManager
- ErrorHandler
- CustomEmailer/PHPMailert
- HttpRequester
- 钩子