PHP code example of groucho75 / phmisk

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

    

groucho75 / phmisk example snippets


$ph4->router->get('/hello', function() {
	
	echo 'Hello world!';
	
});

$demo = new App\Controllers\Demo();

$ph4->router->get('/test', function() use ( $demo ) {
	
	$demo->test();
});

namespace App\Controllers;

class Demo extends Base
{	
	function test() 
	{
		echo 'This page has been created by Test method of Demo custom controller';			
	}

}

$ph4->router->get('/hello/(\w+)', function($name) use ( $ph4 ) {
	
	$ph4->view->assign( 'name', $name );
	$ph4->view->render( 'hello' );
	
});

 

// Assign a variable
$ph4->view->assign( 'name', $name );

// Assign a group of variables
$vars = array( 'name' => 'Foo', 'surname' => 'Bar' );
$ph4->view->assign( $vars );

// Assign a variable, and clean XSS
$ph4->view->assign( 'name', $name, true );

// Echo the ui/home.php view file
$ph4->view->render( 'home' );

// Return the ui/home.php view file as a string
$output = $ph4->view->render( 'home', true );

// Quick php echo
<strong><?=$name

 

$ph4->router->get('/blog', function() use ( $ph4 ) {

	$posts = $ph4->db->from('posts')
			->select('title')
			->limit(5)
			->many();

	$data = array(
		'pagetitle' => 'My posts',
		'posts'		=> $posts,
	);
	
	$ph4->view->assign( $data, true );	
	$ph4->view->render( 'blog' );    
});

 

// Init the session
$ph4->sess->start();

// Set a session var
$ph4->sess->set('my_var', 1);

// Set a flash var (it will exist till next round)
$ph4->sess->setFlash('my_flash_var', 1);

// Get a session var (the 2nd argument is a default if var not found)
$ph4->sess->get('my_var', 0);

define('APP_PATH', '../app');

$log = new Monolog\Logger('name');

phmisk root/
  |
  |__ app/
  |      |__ classes/  
  |      |__ controllers/
  |      |__ core/    
  |      |__ models/
  |      |__ (vendor/)
  |      |
  |      |__ bootstrap.php
  |      |__ config.php
  |      |__ helpers.php  
  |      |__ routes.php
  |
  |__ ui/
  |      |__ css/
  |      |__ fonts/  
  |      |__ img/  
  |      |__ js/    
  |      |
  |      |__ (php view files)  
  |
  |__ composer.json
  |__ index.php
  |__ .htaccess