1. Go to this page and download the library: Download fonqing/wing library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
fonqing / wing example snippets
namespace app\controller;
use wing\core\BaseController;
use wing\core\traits\AutoCrud;
use wing\core\traits\Authorize;
use app\model\News;
use app\model\User;
class NewsController extends BaseController
{
use AutoCrud, Authorize;
public function setup()
{
// When AutoCRUD enabled you should configure the Model class
$this->setModel(News::class);
// Set the uncheck(Skip RBAC check) action for current controller
$this->setUncheckAction('dict');
// Or you can set all uncheck rules for whole application
$this->setUncheckRules([
'module' => ['']
])
// Set current use model for Authorize trait
// The User model must extend \wing\core\BaseModel and implement \wing\core\UserInterface,
// Help your self to get the user id form request token etc.
$this->session->set(User::find(1));
}
// When AuthCRUD enabled, Follow controller action can be used
/*
news/create
news/update
news/index
news/delete
news/detail
news/export (TODO)
*/
/**
* Callback before create data
* @param array $data model data
*/
public function beforeCreate($data) {
$data['user_id'] = $this->session->getUserId();
return $data;
}
}
namespace app\model;
use wing\core\BaseModel;
class News extends BaseModel {
protected $table = 'news';
protected $pk = 'id';
protected $autoWriteTimestamp = true;
protected $createTime = 'create_time';
protected $updateTime = 'update_time';
protected $dateFormat = 'Y-m-d H:i:s';
/**
* Model fields definition, used for search, create, update, index.
*
* @var array
*/
public static array $fields = [
'create' => ['cate_id', 'title', 'cover_image', 'content'],// allow to create fields
'update' => ['cate_id', 'title', 'cover_image', 'content'], // allow update fields
'index' => ['id','cate_id', 'title', 'cover_image', 'content', 'create_time'], // allow index fields
];
/**
* Model data validation rules, used for create and update.
*
* @var array
*/
public static array $rules = [
'create' => [
'cate_id' => '/ Cache for index
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.