1. Go to this page and download the library: Download corneltek/actionkit 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/ */
corneltek / actionkit example snippets
use ActionKit\Action;
class YourAction extends Action
{
public function run() {
}
}
function run() {
return $this->success('Success!!');
}
function run() {
return $this->success('Success', ['user_id' => 1]);
}
function run() {
return $this->error('Error', ['user_id' => 1]);
}
class YourAction extends \ActionKit\Action
{
function schema() {
$this->param('id')
->renderAs('HiddenInput');
$this->param('password')
->renderAs('PasswordInput');
$this->filterOut('hack','hack2','role');
}
function beforeRun() {
// do something
}
function run()
{
return $this->success( 'Success Helper (point to action result object)' );
return $this->error( 'Error Helper (point to action result object)' );
}
function afterRun()
{
// do something
}
}
$act = new Action( $_REQUEST );
$act->invoke();
$rs = $a->getResult();
$runner = ActionKit\Runner::getInstance();
if( $result = $runner->getResult( 'Login::...' ) ) {
// check the action result
}
namespace User\Action\UpdateAction;
use ActionKit\RecordAction\UpdateRecordAction;
class UpdateAction extends UpdateRecordAction {
function schema()
{
// For record actions, we can convert the record columns
$this->useRecordSchema();
$this->param( 'username' )
->label( _('Username') )
->useSuggestion();
$this->param( 'password' )
->validator(function($value) {
if ($value) {
return [false, "reason"];
}
return [true, "success!!"];
});
$this->filterOut(array('auth_token'));
}
function validatePassword( $value , $args )
{
return $this->valid( $message );
# or
return $this->invalid( $message );
}
function suggestUsername( $value , $args ) {
return; # not to suggest
return $this->suggest( "$value is used. use: " , array( ... ) );
}
function completeCountry( $value , $args ) {
...
}
}
function successMessage(OperationResult $ret) {
return _('Your Success Message');
}
function errorMessage(OperationResult $ret) {
return _('Your Error Message');
}
namespace News\Action;
use ActionKit\RecordAction\CreateRecordAction;
class CreateNews extends CreateRecordAction
{
public $recordClass = 'News\Model\News';
}
namespace News\Action;
use ActionKit\RecordAction\UpdateRecordAction;
class UpdateNews extends UpdateRecordAction
{
public $recordClass = 'News\Model\News';
}