PHP code example of eftec / dashone

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

    

eftec / dashone example snippets


use eftec\DashOne\DashOne;
$dash=new DashOne();
$dash->head('Example - test 1'); // it is  renders an empty page

use eftec\DashOne\DashOne;
$dash=new DashOne();

$dash->head('Example - test 1');
$dash->footer();
$dash->render();

use eftec\DashOne\DashOne;
$dash=new DashOne();
$dash->head('Example - test 1')
    ->footer()
    ->render();

// see examples/testuibasic.php
$dash=new DashOne();
$dash->head('Example - test 1')
	->menuUpper(['Upper title'])
	->startcontent()
	->menu($links) // left menu
	->startmain()
	// here it goes the content
	->endmain()
	->endcontent()
	->footer()
	->render();		

$dash->alert("It is an alert","Content of the alert")


$dash->alert("It is an alert","Content of the alert","alert alert-danger")


$buttons=[
	new ButtonOne('button1','Click me','btn btn-primary'),
	new ButtonOne('button2','Click me too','btn btn-danger')
];


$dash->buttons($buttons,false) // where if true then buttons are aligned with the form


	$dash->container("<div class='form-group row'><div class='col-sm-10 offset-sm-2'>%control</div></div>")
		->buttons($buttons)

	$dash->container("<hr>%control<hr>")->rawHtml("hello world")

$currentValue=['IdProduct'=>"2"
	,'Name'=>"aaa"
	,'Price'=>"333"
	,'Type'=>1
	,'Description'=>''];

$dash->form($currentValue) // it's macro of new FormOne()

$definition=['IdProduct'=>'hidden'
	,'Name'=>'text'
	,'Price'=>'text'
	,'Type'=>['cocacola','fanta','sprite']
	,'Description'=>'textarea'];
$currentValue=['IdProduct'=>"2"
	,'Name'=>"aaa"
	,'Price'=>"333"
	,'Type'=>1
	,'Description'=>''];

$dash->form($currentValue,$definition) // it's macro of new FormOne()

$valueUL=['Cocacola','Fanta','Sprite'];

$dash->ul($valueUL) // it's macro of new UlOne()

$values=
	[
		['IdProduct'=>1,'Name'=>'Cocacola','Price'=>"20.2"],
		['IdProduct'=>2,'Name'=>'Fanta','Price'=>"30.5"],
		['IdProduct'=>3,'Name'=>'Sprite','Price'=>"11.5"],
	];

$dash->table($values)->...  // it must be called after the render

$dash=new DashOne();

$dash->head('Example - test 1');
$dash->footer();
$dash->render();

$dash=new DashOne();

$dash->head('Example - test 1');
$dash->menuUpper([new ImageOne('https://via.placeholder.com/32x32')," - ",new LinkOne('Cocacola','#')]);
$dash
	->startcontent() // start the container
		->menu($links) // left menu
		->startmain() // start the main container
			->title('Table of Products')
		->endmain()
	->endcontent();
$dash->footer();
$dash->render();

@session_start(); // or via php.ini

$_SESSION['user'];
// array(5) { ["username"]=> "" ["password"]=> "" ["remember"]=> "" ["_csrf"]=>  "" ["result"]=> bool(true) }

$dash=new DashOne(false,true,'salt_123',['user'=>'john','password'=>'doe']);

$validateLogin= function($user) {
    // this method could access to the database
    return $user['username'] === 'john' && $user['password'] === 'doe';
};
$dash=new DashOne(false,false,'salt_123',$validateLogin);

$user=[];
$dash->fetchLogin($user); // user could returns [ ["username"]=> "" ["password"]=> "" ["remember"]=> "" ["_csrf"]=>  "" ["result"]=> bool(true) ]

if($user['result']) {
    @session_write_close();
    header('location:testlogin2.php');
    die(1);
} else {
    $message='user or password incorrect';
}

$dash->head('Example - test 1','',true) // title of the page, extra content in the header and true= for login page
    ->login($user,null,'Sign-In') // user variable, null or link to the login image and title of the login page
        ->alert($message) // (optional) shows an alert inside the login page
        ->footer() // (optional) shows a footer inside the login
    ->endLogin() // end login container
->render();

session_destroy();
unset($_SESSION['user']);

if (!$dash->checkCSRF()) {
    die(1);
}

if (isset($_SESSION['user']) ) {
	// user has sign-in
} else {
    // user hasn't sign-in
}