PHP code example of pleonovich / simcore

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

    

pleonovich / simcore example snippets


class Config
{
    // MAIN
    const APPID = 'simCore';
    const APPNAME = 'simCore';
    
    // DB CONNECTION
    const DB_HOST = 'localhost';
    const DB_USER = 'root';
    const DB_PASS = '';
    const DB_NAME = 'simCore';
    const DB_CHARSET = 'utf8';
    const DB_PORT = '3307';
    const DB_SOCKET = NULL;
}

Router get ( string $pattern, string $classmethod | Clousure $function [, array $aliases=null ] )
Router post ( string $pattern, string $classmethod | Clousure $function [, array $aliases=null ] )
Router put ( string $pattern, string $classmethod | Clousure $function [, array $aliases=null ] )
Router delete ( string $pattern, string $classmethod | Clousure $function [, array $aliases=null ] )

Router::factory()
->set('~^/$~', 'Index@index') // yourdomain.com
->post('~^/articles/$~', 'Index@addArticle') // yourdomain.com/id/7
->put('~^/articles/([0-9]+)$~', 'Index@updateArticle', array('id')) // yourdomain.com/id/7
->delete('~^/articles/([0-9]+)$~', 'Index@deleteArticle', array('id')) // yourdomain.com/id/7
->get('~^/func$~', function ($request, $response) {
	echo "Hello world!";
})
->run();

SimpleRouter setDefault ( string $class, string $method )
SimpleRouter set ( string $mod, string $class, string $method )

SimpleRouter::factory()
->setDefault('Index', 'index') // yourdomain.com
->get('main', 'Index', 'index') // yourdomain.com?mod=main&id=7
->run();

class Userlist extends Model {

  protected static $table = 'userslist';
  
}

class Userlist extends Model {

  protected static $table = 'userslist';
  
  protected static function schema($create) {
        $create
        ->id()
        ->varchar('user_name')
        ->varchar('user_login')
        ->varchar('email')
        ->text('secret')
        ->int('manager')
        ->int('moderator');
   }
}

Userlist::migrate();

class Userlist extends Model {

 protected static $table = 'userslist';
  
 protected static function insert($insert) {
        $insert
        ->set('user_name', 'Admin')
        ->set('user_login', 'admin')
        ->set('secret', '12345')
        ->set('manager', '1')
        ->set('moderator', '1');
	}
}

Userlist::insertData();

// returns all data from table
Array all () 
// returns only specific columns from table
Array getNames ( mix ... ) 
// returns one specific column
Array column ( string $name ) 
// return one specific row by id
Array getById ( int $id ) 
// return one row by id specific column and its value
Array getByValue ( string $name, string $value ) 
// return specific rows by id specific column and its value
Array namesByValue ( Array $names, string $name, string $value ) 
// updates data in db from POST, inserts if id not exist.
Boolean save () 
// removes data by id
Boolean remove ( string $name, string $value ) 

Model
class IndexController {

  public function Index () {   
    $data = Pages::getById(7);
    print_r($data);
  }
  
}

{{

#src/views/layout.view.php
<h1>Title</h1>
{{}
{{block content}}
<p>Here some text</p>
{{/block content}}

Description:
Void|string render( string $file [, boolean $return = false ] )

Example:
View::factory()->render('home');

Output:
<h1>Title</h1>
<p>Here some text</p>

class Controller extends abstractController {

  protected $title;
  protected $content;
	
  public function __construct () {
    parent::__construct();
  }	
  // PAGE WHEN ACCESS DENIED
  protected function accessDenied () {
    View::factory()->render('accessdenied');
  }
  // PAGE FOR 404
  protected function action404 () {
    View::factory()->render('action404');
  }
  // LAYOUT VIEW
  protected function render () {
    View::factory()
    ->bind("title",$this->title)
    ->bind("content",$this->content)
    ->render('layout'); // view name without prefix
  }

}

class IndexController extends Controller {

  public function Index () {
    $this->title = "Hello world!";
    $this->content = "Here is some text for our first page";
    // MAIN RENDER
    $this->render();
  }
  
}
/simcore/config/Config.class.php
index.php
Model.class.php
layout.view.php
html
// Set variables
{{var myvar='hello'}}
//The same as:
 $name='hello'
html
{{foreach $array as $one}}
<p>{{$one}}</p>
{{/foreach}}

// The same as:
 foreach ($array as $one): 
html
{{for ($a=1;$a<7;$a++)}}
<p>{{$a}}</p>
{{/for}}

// The same as:
 for($a=1;$a<7;$a++): 
html
{{if $var}}
<p>true</p>
{{else}}
<p>false</p>
{{/if}}

// The same as:
 if($var):