PHP code example of codemini / framework

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

    

codemini / framework example snippets




$dirname = strtolower(basename(__DIR__));

if($dirname == 'public') {
    catch (Exception $e) {

    $e->getMessage();

} //end try...catch

$config['base_url'] = 'http://localhost:8080/';

$config['environment'] = 'development';

$config['mysql'] = [
    'host'     => 'localhost',
    'dbname'   => 'codemini_tests',
    'username' => 'root',
    'password' => '',
    'charset'  => 'utf8',
    'display_error' => ($config['environment'] == 'development') ? true : false
];

$config['session_name'] = 'MY_Session_name_';

$config['timezone'] = 'America/Sao_Paulo';

$config['page_not_found'] = 'PageNotFound@index';

$config['view_extension'] = '.phtml';

 
namespace App\Controllers;

use Codemini\Core\Controller;
use Codemini\Core\Request;

class Home extends Controller{

    public function __construct(){
        parent::__construct();
    }

    public function index($args=""){
        
        //Data to view
        //Example: $this->view->data = ['php', 'js', 'nodejs', 'mongodb', 'css'];

		//Load view
		//$this->view('template_name');
		
		echo "Controller name: " . Request::getController() . "<br>";
         echo "Method name: " . Request::getMethod() . "<br>";
    }

}

 
namespace App\Models;

use Codemini\Core\Model;

class Products extends Model{

	protected $table = 'table_name';

	/**
	 * Construct the parent model class for get instance '$this->db' PDO and the 
	 * SIMPLE QUERY BUILDER functions
	 */
	public function __construct()
	{
		parent::__construct();
	}

	/**
	 * Example 1 with VERY SIMPLE query builder
	 */
	public function allProducts($orderBy = "ORDER BY `name` ASC"){
		$sql = "SELECT * FROM `{$this->table}` {$orderBy}";
		$this->query($sql);
		$this->execute();
		return $this->fetchAll();
	}

	/**
	 * Example 2 with VERY SIMPLE query builder
	 */
	public function productById($val)
	{
		$sql = "SELECT * FROM `{$this->table}` WHERE `id` = :id";
		$this->query($sql);
		$this->bind(":id", $val);
		$this->execute();
		return $this->fetch();
	}

	/**
	 * Example 3 with VERY SIMPLE query builder
	 */
	public function productsByPrice($val)
	{
		$sql = "SELECT * FROM `{$this->table}` WHERE `price` = :price";
		$this->query($sql);
		$this->execute([":price" => $val]);
		return $this->fetchAll();
	}

	/**
	 * Example 4 with MANUALLY statement $db
	 */
	public function productsByName($val)
	{
		$sql = "SELECT * FROM `{$this->table}` WHERE `name` = :name";
		$stmt = $this->db->prepare($sql);
		$stmt->bindParam(":name", $val, \PDO::PARAM_STR);
		$stmt->execute();
		return $stmt->fetch();
	}
}
 
 
namespace App\Controllers;

//IMPORTANT
// Don't forget to load with 'use' instruction
use Codemini\Core\Controller;
use Codemini\Libraries\Input;

class Teste extends Controller{

    public function __construct(){
        parent::__construct();
    }

    public function index($args){
        //$_POST
        $email = Input::post('email');
        $password = Input::post('password');
       
        //$_GET
        $email = Input::get('email');
        $password = Input::get('password');
        
        //FILE
        $userfile = Input::file('userfile');
        
        //ALL REQUEST
        print_r($allRequest = Input::all());
    }

}

 

namespace App\Helpers;

class Upload
{
	public static function setUpload($file) 
	{
		//The logic code here...
	}
}

 
namespace App\Controllers;

use Codemini\Core\Controller;

// IMPORTANT:
// Don't forget load the helper librarie you have created
use App\Helpers\Upload;

class Home extends Controller{

    public function __construct(){
        parent::__construct();
    }

    public function index($args=""){
        // call methods
        Upload::setUpload($_FILE['userfile']);
    }

}
 echo configItem('base_url')