Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /** MODEL **/
- include(APPPATH.DIRECTORY_SEPARATOR.'core'.DIRECTORY_SEPARATOR.'API_ORM_Model.php');
- // Tokens model
- class Tokens_model extends API_ORM_Model {
- public function __construct() {
- parent::__construct();
- $this->load->database();
- $this->table = 'tokens';
- $this->fields = [
- 'id' => new ORM_Field_Int([
- 'pkey' => true,
- 'auto' => true
- ]),
- 'name' => new ORM_Field_String([
- 'label' => 'Name',
- 'required' => true,
- 'trim' => true,
- 'unique' => true,
- ]),
- 'host' => new ORM_Field_String([
- 'label' => 'Host',
- 'trim' => true,
- 'required' => true,
- 'validators' => function () {
- return preg_match('/^'.RE_HOST.'$/', $this->val)? True : 'Wrong host format';
- }
- ]),
- 'token' => new ORM_Field_String([
- 'label' => 'Token',
- 'generated' => true,
- 'generator' => function () {
- return hash('sha256', time().rand(1, 10000000000));
- }
- ])
- ];
- }
- }
- /** CONTROLLER **/
- include(APPPATH.DIRECTORY_SEPARATOR.'core'.DIRECTORY_SEPARATOR.'API_CRUD_Controller.php');
- // Tokens controller
- class Tokens extends API_CRUD_Controller {
- public function __construct() {
- parent::__construct();
- $this->path = [
- ['Tokens', '/tokens']
- ];
- $this->model('tokens_model');
- }
- public function index() {
- $this->grid();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment