1. Go to this page and download the library: Download daycry/restful 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/ */
daycry / restful example snippets
namespace App\Controllers;
use CodeIgniter\RESTful\ResourceController;
use Daycry\RestFul\RestFul;
use Daycry\RestFul\Traits\Authenticable;
class Center extends ResourceController
{
use RestFul;
use Authenticable;
public function index()
{
return $this->respond( $this->content );
}
}
If you need to validate the data, you can call `validation` method passing the string rules, array of data and Validation Config file if you need.
By default load `App\Config\Validation.php` rules.
For Example: `app/Config/Validation.php` or if rules are in custom namespace `app/Modules/Example/Config/Validation.php`
namespace App\Controllers;
use CodeIgniter\RESTful\ResourceController;
use Daycry\RestFul\RestFul;
use Daycry\RestFul\Traits\Authenticable;
use Daycry\RestFul\Traits\Validation;
class Center extends ResourceController
{
use RestFul;
use Authenticable;
use Validation;
public function index()
{
$this->validation( '
namespace App\Controllers;
use CodeIgniter\RESTful\ResourceController;
use Daycry\RestFul\RestFul;
use Daycry\RestFul\Traits\Authenticable;
use Daycry\RestFul\Traits\Validation;
class Center extends ResourceController
{
use RestFul;
use Authenticable;
use Validation;
public function index()
{
$this->validation( '
namespace App\Models;
use CodeIgniter\Validation\ValidationInterface;
use CodeIgniter\Database\ConnectionInterface;
use Daycry\RestFul\Models\UserModel as RestFulUserModel
class UserModel extends RestFulUserModel
{
protected $allowedFields = [
'username',
'scopes'
];
public function __construct(?ConnectionInterface &$db = null, ?ValidationInterface $validation = null)
{
parent::__construct($db, $validation);
}
}
public string $userProvider = \Daycry\RestFul\Models\UserModel::class;
namespace App\Exceptions;
use Daycry\RestFul\Exceptions\RuntimeException;
class CustomException extends RuntimeException
{
protected $code = 401;
public static $authorized = true;
public static function forInvalidPassphrase()
{
self::$authorized = false;
return new self(lang('Secret.invalidPassphrase'));
}
public static function forInvalidToken()
{
self::$authorized = false;
return new self(lang('Secret.invalidToken'));
}
public static function forExpiredToken()
{
self::$authorized = false;
return new self(lang('Secret.tokenExpired'));
}
public static function forTokenReaded()
{
self::$authorized = false;
return new self(lang('Secret.readed'));
}
}
php spark restful:discover
/**
*--------------------------------------------------------------------------
* Cronjob
*--------------------------------------------------------------------------
*
* Set to TRUE to enable Cronjob for fill the table petitions with your API classes
* $restNamespaceScope \Namespace\Class or \Namespace\Folder\Class or \Namespace example: \App\Controllers
*
* This feature use Daycry\CronJob vendor
* for more information: https://github.com/daycry/cronjob
*
*/
public array $namespaceScope = ['\App\Controllers', '\Api\Controllers'];
/*
|--------------------------------------------------------------------------
| Cronjobs
|--------------------------------------------------------------------------
|
| Register any tasks within this method for the application.
| Called by the TaskRunner.
|
| @param Scheduler $schedule
*/
public function init(Scheduler $schedule)
{
$schedule->command('restful:discover')->named('discoverRestful')->daily();
or
$schedule->command('restful:discover')->named('discoverRestful')->daily('11:30 am');
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.