PHP code example of chkn / core

1. Go to this page and download the library: Download chkn/core 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/ */

    

chkn / core example snippets



namespace http\Controllers;

use App\Controller\Controller;
use App\App\Request;

class homeController extends Controller{
	public function home(){
		return scene("index","homepage/index")
			->title("Hello World")
			->show();
	}
}




//your controller 

namespace http\Controllers;

use App\Controller\Controller;
use App\App\Request;

class homeController extends Controller{
	public function home(){
		return scene("index","homepage/index")
			->title("Hello World")->bind([
				"variable_name"=>"value"
			])
			->show();
	}
} 

//your controller 
$array = [
     0=> ["name"=> "Ben","age"=> "25"],
     1=> ["name"=> "Anna","age"=> "24"]
];

namespace http\Controllers;

use App\Controller\Controller;
use App\App\Request;

class homeController extends Controller{
	public function home(){
		return scene("index","homepage/index")
			->title("Hello World")
			->bind([
				"variable_name"=>$array
			])
			->show();
	}
} 

//your controller 

namespace http\Controllers;

use App\Controller\Controller;
use App\App\Request;

class homeController extends Controller{
	public function home(){
		return scene("index","homepage/index")
			->title("Hello World")
			->bind([
				"type"=>"active"
			])
			->show();
	}
} 

public function fetchData(Request $r){
	$name = $r->name;
	$address = $r->address;
	$age = $r->age;
}

use App\Database\DB;

public function select(Request $r){
	$data = DB::select("table")->fetch();
}

public function select(Request $r){
	$data = DB::select("table")
			->where("table_field","=","value")
			->fetch();
}

public function select(Request $r){
	$data = DB::select("table")
			->join("other_table","table.field","=","other_table.field")
			->where("table.field","=","value")
			->fetch();
}

public function select(Request $r){
	$data = DB::select("table")
			->limit(1)
			->fetch();
}

public function select(Request $r){
	DB::select("table")
		->orderBy("table_field","ASC")
		->fetch();
}

public function insert(Request $r){
	$data = DB::insert("table")
			->field("field_name","value")
			->field("field_name","value")
			->field("field_name","value")
			->execute();
}

public function delete(Request $r){
	$data = DB::delete("table")
			->where("field_name","=","value")
			->execute();
}

public function update(Request $r){
	$data = DB::update("table")
			->field("field_name","value")
			->field("field_name","value")
			->field("field_name","value")
			->where("field_name","=","value")
			->execute();
}

public function query(Request $r){
	$data = DB::query("SELECT * FROM table WHERE field={field}")
			->bind("field","value of field")
			->execute();
}

// Include the class Session
use App\App\Session;


// In a method
Session::put("session_name","session_value");


// Include the class Session
use App\App\Session;


// In a method
Session::clear("session_name");


// Include the class Session
use App\App\Session;


// In a method
Session::get("session_name");


// Include the class Session
use App\App\Session;


// In a method
Session::check("session_name");



// In a method
encrypt("string to encrypt");

// base64
seal("string to encrypt");

// Selected column in an array (base64)
array_seal($array,$key);



// In a method
decrypt("encrypted string");

// base64
rseal("encrypted string");


// Dump data in the application
dd($var);

// Dump date time in the application
ddt($message);

upload($file_location,$image,$image_name);

download($filename,$file_location)


locate("location");

echo response(["message"=>"success"],200);



// Module
namespace http\Module;
use App\Controller\Controller;
use App\Database\DB;
class Module extends Controller{
    public static function sample(){
	return "Hello World"
    }
}

//Controller

namespace http\Controllers;

use App\Controller\Controller;
use App\App\Request;
use http\Module\Module;

// Include the Module Class
use http\Module\Module;

class sampleController extends Controller{
    public function home(Request $r){
	// It will display Hello World in sample/home
	echo Module::sample();
    }
}



// Module
namespace http\Controller;
use App\Controller\Controller;
use App\Controller\Auth;


class homeController extends Controller{
    public static function home(){
		Auth::check(["role"=>"admin"],"auth");
    }
}



// Module
namespace http\Controller;
use App\Controller\Controller;
use App\Controller\Auth;

class homeController extends Controller{
    public static function home(){
		Auth::check(["role"=>"admin,staff,cashier"],"auth");
    }
}