PHP code example of micky / mkyengine
1. Go to this page and download the library: Download micky/mkyengine 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/ */
micky / mkyengine example snippets
// index.php
$this->extends('layout')
// layout.php
<h4>Layout</h4>
<?= $this->section('content')
$loader = new \MkyEngine\DirectoryLoader('views_dir');
$loader->setComponentDir('components_dir')->setLayoutDir('layouts_dir');
$context = [] // Shared environment variables, optional
$environment = new \MkyEngine\Environment($loader, $context);
$environment->addLoader('ns2', $loader2);
// Check if loader exists
$environment->hasLoader('ns2'); // true
<?= $this->component('form')
$view = new \MkyEngine\ViewCompile($environment, 'index', [
'name' => 'Micky'
]);
echo $view->render();
// layout.php
<h4>Layout</h4>
<?= $this->section('content')
// layout.php
<?= $this->section('title', 'default')
// layout.php
$this->extends('great-layout')
// layout.php
<?= $this->section('title', 'title')
$this->extends('layout')
$this->extends('layout')
$this->extends('layout')
// layout.php
<h4>Layout</h4>
<?= $this->section('content')
$this->block('content')
$this->block('content')->if($condition)
class FormBuilder
{
public function open(array $attr): string
{
return "<form method='{$attr['method']}' action='{$attr['action']}'>";
}
public function input(string $type, string $name, string $value = ''): string
{
return "<input type='$type' name='$name' value='$value'>";
}
public function submit(string $message, string $name = ''): string
{
return "<button type='submit'" . ($name ? " name='$name'" : '') . ">$message</button>";
}
public function close(): string
{
return "</form>";
}
}
// view.php
$this->inject('form', FormBuilder::class)
$this->inject('form', FormBuilder::class)
<?= $this->component('form')
<?= $this->component('form')->bind('name', 'Micky')
<?= $this->component('form')->multipleBind(['name' => 'Micky', 'lastname' => 'Ndinga'])
<?= $this->component('form')->if($condition)
// components/name-input.php
<input value="<?= $name
<?= $this->component('name-input')->for(3, function(array $params, int $index) use ($users){
$params['name'] = $users[$index]->name;
return $params;
})
<?= $this->component('name-input')->each($users, function(array $params, int $index, array $users){
$params['name'] = $users[$index]->name;
return $params;
})
<?= $this->component('name-input')->each($users, ['name'])
// components/user-input.php
<input value="<?= $user->name
<?= $this->component('user-input')->each($users, 'user', 'empty-user')
// components/alert.php
<div class="alert alert-<?= $type
// view
$this->component('alert')->bind('type', 'danger')
$this->addslot('close', 'Close info')->if($type == 'info')
<?= $this->slot('default', 'default text')