Mini PHP Framework - Erstellen Sie eine schnelle Anwendung mit Standard -MVC -Struktur.
Leia Na Versão em Português (Pt-BR): Português Pt-BR
Warum Codemini verwenden?
Wenn Sie aus irgendeinen Gründen keine komplexe Struktur verwenden möchten und nicht festgebunden werden möchten, ist Codemini für Sie eine Option.
Codemini ist sehr einfach zu bedienen. Sie können Ihr Projekt in public Ordner wie Laravel, Codesigniter 4 ausführen oder wenn Sie den gemeinsam genutzten Host verwenden, einfach index.php und .htaccess vom öffentlichen Ordner in den Root -Ordner kopieren und alle Dinge, die gut funktionieren.
Sie können einfach andere Pakete von packagist.org in Ihr Projekt verwenden composer require <vendor>/<package>
Drittanbieter -Tools wie WAMP oder XAMPP
Wenn Sie oben traurig sind, kopieren Sie einfach index.php und .htaccess vom öffentlichen Ordner in den Root -Ordner und alle Dinge, die gut funktionieren.
Beispiel:
www oder htdocsindex.php und .htaccess aus dem öffentlichen Ordner in den Root -OrdnerHinweis: Entfernen Sie den öffentlichen Ordner, wenn Sie möchten
Warum tun es?
Denn wenn Sie Tools wie WAMP oder XAMPP verwenden, ist das Documentroot von Apache auf den Root -Ordner www (WAMP) oder HTDOCs (XAMPP) und nicht zum öffentlichen Ordner des Frameworks.
Diese Regel gilt nicht nur für Codemini, sondern auch für Codesigniter 4, Laravel usw. Dies ist die Art und Weise, wie das Framework funktioniert.
1- Wenn Sie als Composer-Projekt installieren möchten, rennen Sie: composer create-project --prefer-dist codemini/framework name-folder-of-you-project
2- Offene Klemme und Run Cli-Tools: php cli-tools serve
Optional: Mit PHP -integriertem Server ausführen, zum public Ordner gehen und ausführen: php -S localhost:8080
Hinweis: In diesem Fall ist es nicht erforderlich, die Komponist-Installation auszuführen, da der Composer Create-Project dies bereits für Sie ausführt.
1 - Wenn Sie mit Git Clone installieren möchten, rennen Sie: git clone https://github.com/fabriciopolito/Codemini.git oder Download "Download ZIP" und extrahieren Dateien.
2 - Komponist ausführen (erforderlich) im Stammprojektordner, in dem Composer.json enthält, um Autoloaddateien zu erstellen.
composer installphp composer.phar install haben 3- Offene Klemme und Laufcli-Tools: php cli-tools serve
Optional: Mit PHP -integriertem Server ausführen, zum public Ordner gehen und ausführen: php -S localhost:8080
Ihr index.php sollte so aussehen:
<?php
$ dirname = strtolower ( basename ( __DIR__ ));
if ( $ dirname == ' public ' ) {
require_once ' ../app/Init.php ' ;
} else {
require_once ' app/Init.php ' ;
}
try {
$ myAPP = new Init ();
} catch ( Exception $ e ) {
$ e -> getMessage ();
} //end try...catch Hinweis: Codemini hat nicht viele Konfigurationen.
Ändern Sie Standards -Dateien:
Config.php - Konfiguration auf Base_url, MySQL, Umgebung, TimeZone usw. definierenBeispiel:
$ 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 ' ;Hinweis: Die Datei -App/config.php verfügt über die vollständige Option in jeder Option
Constants.php - Definieren Sie Ihren Projektnamen und Ihren Dateienspeicherort... und erstellen Sie Ihre Controller, Ansichten und Modelle!
Controller / Home.php
php cli-tools create-controller HomeAusgabe: ./app/controllers/home.php
<?php
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> " ;
}
} Ansichten / Template/index.phtml
<!doctype html >
< html lang =" en " >
< head >
<!-- Required meta tags -->
< meta charset =" utf-8 " >
< meta name =" viewport " content =" width=device-width, initial-scale=1, shrink-to-fit=no " >
< base href =" <?php echo $config['base_url'] ?> " >
<!-- Bootstrap CSS -->
< link rel =" stylesheet " href =" https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css " integrity =" sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh " crossorigin =" anonymous " >
< title > Application name </ title >
</ head >
< body >
< ?php
print ' < pre > ';
print_r($this- > view- > data);
print ' </ pre > ';
? >
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
< script src =" https://code.jquery.com/jquery-3.4.1.slim.min.js " integrity =" sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n " crossorigin =" anonymous " > </ script >
< script src =" https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js " integrity =" sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo " crossorigin =" anonymous " > </ script >
< script src =" https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js " integrity =" sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6 " crossorigin =" anonymous " > </ script >
</ body >
</ html > Modelle / Products.php
php cli-tools create-model ProductsAusgabe: ./app/models/products.php
<?php
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 ();
}
} configItem('key') Gibt den konfigurierten Namen zurück. Beispiel: <?php echo configItem('base_url') ?>
&getInstance() Rückgabe -Controller -Objektinstanz
Wie benutze ich Librarie im Controller?
Es ist sehr einfach! Laden Sie es einfach mit use und die Librarie steht Ihnen zur Verfügung.
Beispiel:
<?php
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 ());
}
}Die grundlegenden Bibliotheken von Codemini
Input - Helfen Sie Ihnen, Get, Post, Datei zu manipulierenecho Input::get('email')echo Input::post('email')echo Input::file('userfile')echo Input::all()Redirect - Benutzer an einen anderen Ort umleitenecho Redirect::to(configItem('base_url') . 'login/index')Session - Helfen Sie Ihnen, Sitzungsdaten zu manipulierenSession::start()Session::set('logged_in', true)Session::set(array('user_id' => 1, 'logged_in' => true))Session::get('user_id')Session::has('logged_in')Session::all()Session::id()Session::regenerateId()Session::remove('user_id')Session::destroy()Validator - Helfen Sie, Daten zu validierenValidator::getErrors()Validator::getMsg()Validator::setOpenTag('<p>')Validator::setCloseTag('</p>')Validator::required($val)Validator::isEmail($val)Validator::isUrl($val)Validator::isFloat($val)Validator::isInt($val)Validator::isBool($val)Validator::isIp($val)Validator::regex($val, '/[az]/i')Hinweis: Die Bibliotheken haben in jeder Option die vollständige Dokumentation.
Du bist frei! Erstellen Sie also einen Helpers in ./app/ und eine Datei Upload.php , und das einzige, was Sie tun müssen, ist, den richtigen Namespace für das autolading zu setzen.
Beispiel ./app/Helpers/Upload.php :
<?php
namespace App Helpers ;
class Upload
{
public static function setUpload ( $ file )
{
//The logic code here...
}
}Und verwenden Sie es dann in jedem Controller auf diese Weise:
Beispiel ./app/Controllers/Home.php
<?php
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 ' ]);
}
}Es ist sehr einfach! Führen Sie den Befehlskomponisten an und laden Sie ihn oben genauso.
Beispiel 1: composer require plasticbrain/php-flash-messages
Beispiel 2: composer require monolog/monolog
Fabricio Pólito - [email protected] - https://github.com/fabriciopolito
Danke es mit es?
Codemini ist unter der MIT -Lizenz lizenziert ✔️