Janggelan是一個意外的PHP框架,可讓您輕鬆。它很簡單,但功能強大且愉悅。就像其他框架一樣,在嘗試理解Janggelan時,您不會遇到困難。
Janggelan是根據MVC概念而設計的,並重點關注。因此,我們試圖避免將MVC系統與其他可能有助於您開發的工具合併,因為它可以降低性能。當然,我們一直將其封閉,以幫助您的發展,但它將帶有不同的封面。
請閱讀文檔以獲取更多信息。
我們知道我們無法完美完成此框架,也許與您想要的內容不符。但是,我們總是試圖更好地完成它,並使您出乎意料。您可以與我們一起貢獻。
添加了一些新工具。
重寫了所有Janggelan的腳本,以獲得新的更好的性能。
減少一些服務器負載。
添加了一些新的Model方法: where() , exec() , execute() 。
添加了文檔。
在.htaccess上使用的緩存和壓縮gZip 。
PHP 7
PDO PHP擴展
下載Janggelan的文件,將其提取到您的應用程序目錄。
如果要發布或安裝Janggelan用於共享託管,最安全的方法是將Janggelan的文件和目錄放置在server root的內部,然後將public文件夾的所有內容移至public_html或www中。
您將從public / public_html / www目錄運行您的應用程序。
如果您在安裝後發現問題,請檢查文件權限。
__ backend/
|__ .secrets/
|__ config/
|__ framework/
|__ global/
|__ register/
|__ vendor/
|__ autoload.php
|__ composer.json
|__ force.uri
__ public/
|__ assets/
|__ .htaccess
|__ index.php
__ worksheet/
|__ controllers/
|__ model/
|__ providers/
|__ tools/
|__ views/
|__ requests.php
在您的服務器中,讓我們第一次運行Janggelan。確保您的系統已經完成了System Requirements和上面的installation 。
轉到Janggelan文件放置的應用程序目錄。輸入到public文件夾。例如,在Linux中,您可以完成此操作:
cd /var/www/html/your_application/public打開Localhost服務器:
php -S localhost:8000或者,您可以直接使用此命令進行操作:
php -S localhost:8000 -t /var/www/html/your_application/public現在,打開瀏覽器,然後訪問Localhost:8000。
在Janggelan中,您將其稱為requests 。在其他PHP框架(例如Laravel)中,這將其稱為routes 。 Janggelan中的每個請求都在文件worksheet/requests.php上處理。要創建一個新的請求,請轉到該文件。在那裡您會看到這樣的request示例:
$ this -> request ( ' GET / @Hello::world ' );上面的示例意味著:“請求URI /使用請求方法GET 。如果用戶訪問/和URI有效,它將被重定向,並以方法 /功能world方式繼續前往控制器Hello ''。基於示例,現在您可以使用以下選項創建自定義請求:(參數或參數1被space分開):
// Redirected to Controller.
// Request method can be 'GET' or 'POST'
$ this -> request ( ' GET /home @Hello::world ' );
// Redirected to View.
$ this -> request ( ' GET /home (viewName) ' );
// Redirected to Controller with Protected Rule 'login'.
$ this -> request ( ' GET /home @Hello::world !!login ' );
// Redirected to View with Protected Rule 'login'.
$ this -> request ( ' GET /home (viewName) !!login ' );
// Will proceed the Closure or Callback directly.
$ this -> request ( ' GET /home ' , function ()
{
// Do some stuff...
});
// Will proceed the Closure or Callback directly with Protected Rule 'login'.
$ this -> request ( ' GET /home !!login ' , function ()
{
// Do some stuff...
});稍後您將了解有關受Protected Rule更多信息。請注意,僅在進行測試時使用Closure或Callback 。我們始終建議將View或Controller用作重定向。
Controller s放置在worksheet/controllers中。嘗試使用創建新文件創建新的Controller ,假設文件名是MyController.php 。然後,在MyController.php中,編寫此基本Controller樣式:
<?php namespace controller ;
class MyController extends framework parents Controller
{
public function welcome ()
{
echo ' Welcome to my Controller. ' ;
}
}在worksheet/requests.php上,添加將繼續Controller新請求。
$ this -> request ( ' GET /test @MyController::welcome ' );現在,在瀏覽器上訪問/test 。如果一切正常,您會看到輸出: Welcome to my Controller. 。 Controller文件名必須相同,並與Controller類名稱匹配。另外,您必須關心Namespace 。如果您在新目錄中創建控制器:
__ controllers/
|__ my_new_folder/
|__ MyController.php
然後,您的Controller的Namespace應該是這樣:(這也適用於所有名稱空間系統)
<?php namespace controllers my_new_folder ;
class MyController extends framework parents Controller
{
//
}如果您的frameworkparentsController不需要使用某些內置功能,例如$this->LOAD_VIEW() Controller $this->GET_RULE() ,et。
Model被放置在worksheet/models中。 Model用於與數據庫進行通信。因此,當您創建Model時,請確保它與數據庫中的數據對應。要使用Model ,您必須在backend/.secrets/.db中設置數據庫配置,或查看有關Configuring Database文檔。
上述完成後,讓我們嘗試創建Model 。首先,在worksheet/models中創建一個新文件。假設文件名是User.php 。然後,使用此基本Model樣式編寫文件的內容:
<?php namespace model ;
class User extends framework parents Model
{
// This is your table name. It is required by system.
protected static $ table = ' user ' ;
// This is your table columns. Only required if you want to create new
// table into Database.
protected static $ columns = [
' id ' => ' INT(11) AUTO_INCREMENT PRIMARY KEY ' ,
' username ' => ' VARCHAR(255) NOT NULL ' ,
' password ' => ' VARCHAR(255) NOT NULL '
];
}在您的Controller中,調用Model類:
<?php namespace controller ;
use model User ;
class MyController extends framework parents Controller
{
public function workingWithModel ()
{
// Initialize object of Model 'User'.
// Now you can use your Model.
$ user = new User ;
}
}如果您之前沒有具有名稱user的表,只需使用create()方法在運行Controller Method workingWithModel()時自動創建表即可。
$ user = new User ;
// this will create new table into Database with columns and properties that
// already defined on 'protected static $columns'.
$ user -> create ();幾乎完成了,現在您只需要使用一些內置功能或方法的Model即可。
$ user = new User ;
// Open Database connection manually. Only needed if 'auto_connect' config is FALSE.
$ user -> open ();
// Close Database connection manually. Only needed if 'auto_connect' config is FALSE.
$ user -> close ();
// Delete all data in Model 'User' | table 'user'.
$ user -> delete ();
// Delete all data in Model 'User' | table 'user' | where id = 1 and username = name.
$ user -> delete ([ ' id ' => 1 , ' username ' => ' name ' ]);
// Insert new data to Model 'User' | table 'user' | to column username with value
// 'Linus Torvald'.
$ user -> insert ([ ' username ' => ' Linus Torvald ' ]);
// Update data in Model 'User' | table 'user' | where id = 1. Update username
// to value 'Linus Torvald'.
$ user -> update ([ ' username ' => ' Linus Torvald ' ], [ ' id ' => 1 ]);
// Get all data from Model 'User' | table 'user'.
$ user -> get ();
// Get 5 data results from Model 'User' | table 'user'.
$ user -> get ( 5 );
// Select all data from column 'username' of Model 'User' | table 'user'.
$ user -> select ( ' username ' )-> get ();
// Get data from column 'username' of Model 'User' | table 'user' | take 4 data results
// start from data number 2.
$ user -> range ( 4 , 2 )-> get ();
// Get data from Model 'User' | table 'user' | based on the clause 'WHERE id = 1'.
// You can do anything inside of 'clause()'.
$ user -> clause ( ' WHERE id = 1 ' )-> get ();
// Select data from column 'username' of Model 'User' | table 'user' |
// where id = 1 AND username = 'Linus Torvald'.
$ user -> where ([ ' id ' => 1 , ' username ' => ' Linus Torvald ' ])-> get ();
// Exec query.
// 'query' is anything sql queries such as 'DELETE * FROM' or 'SELECT *'.
$ user -> exec (query);
// Execute query with bind params (PDO prepare statement).
$ user -> execute (query, bindParams);
// You can custom you queries with chaining functions or methods like this:
$ user -> select ( ' username ' )-> range ( 4 , 2 )-> get ();
// Using prepare statement
$ user -> clause ( ' WHERE id=:id ' )-> bindParams ([ ' id ' => 1 ])-> get (); View S放置在worksheet/views中。基本上, View是模板,它可以是HTML或PHP代碼。沒有任何特殊的View規則。但是,在Janggelan中, View擴展總是.php 。您可以在View中寫入任何代碼。要使用View ,您只需要稱呼它。例子:
// Calling View 'example.php' on requests.php
// Note that you cannot calling View with Closure or Callback.
$ this -> request ( ' GET / (example) ' );
// Calling View 'example.php' inside folder 'new_folder' on requests.php
$ this -> request ( ' GET / (new_folder/example) ' );
// Calling View 'example.php' on Controller
$ this -> LOAD_VIEW ( ' example ' );
// Calling View 'example.php' inside folder 'new_folder' on Controller
$ this -> LOAD_VIEW ( ' new_folder/example ' );如果您想將View在public或public_html或www目錄中的任何地方放置在worksheet/views之外,則只需添加/ :
$ this -> request ( ' GET / (/example) ' );
$ this -> LOAD_VIEW ( ' /example ' );這將告訴系統在public/example.php或public_html/example.php或www/example.php上找到View 。
現在,如何View數據。實際上,您可以簡單地做到這一點。只需compact()數據:請注意,只有在通過Controller調用View時才能傳遞數據。
$ data = ' This is data ' ;
$ this -> LOAD_VIEW ( ' example ' , compact ( ' data ' ));然後,在View文件example.php上,只需調用變量:
<p> <?php echo $ data ; ?> </p> Janggelan提供了一些您可以使用的工具,並且可能對開發案例有用。它們被放置在worksheet/tools中。要使用它們,只需要調用他們的班級名稱即可。例子:
<?php namespace controller ;
use tool Validation ;
class Example extends framework parents Controller
{
private $ validation ;
function __construct ()
{
$ this -> validation = new Validation ;
}
} Protected Rule是Janggelan中的系統,可以像登錄系統一樣保護您的page , View或Uri 。 Protected Rule存儲的匿名數據,這些數據始終在request使用此系統時檢查。如果訪問的用戶沒有有效的匿名數據,則將自動將用戶自動重定向到以前已定義的target中。這將輕鬆保護要私有或僅適用於某些用戶的頁面。
要製定新的Protected Rule ,請轉到backend/config/protected.php上的配置文件。您可以製定多個受Protected Rule 。例子:
<?php return [
// FALSE means, system will uses SESSION to store protected_rule data. Set it TRUE
// if you want to store the data in COOKIE.
' use_cookie ' => FALSE ,
' protected_rule ' => [
// Creating 'Protected Rule' with name 'login'.
// If the data is not valid, then redirect to Controller 'Example'
// method 'protected.'
' login ' => [
' on_false ' => [
' controller ' => ' Example ' ,
' method ' => ' protected '
],
],
// Creating 'Protected Rule' with name 'protect'.
// If the data is not valid, then redirect to View 'example'.
' protect ' => [
' on_false ' => [
' view ' => ' example ' ,
],
],
// Creating 'Protected Rule' with name 'myRule'.
// If the data is not valid, then redirect to uri '/wrong'.
' myRule ' => [
' on_false ' => ' /wrong '
],
]
];然後,要應用該Protected Rule ,請轉到worksheet/requests.php ,然後添加新Request :(語法為!! ):
// Applying Protected Rule 'login'.
$ this -> request ( ' GET / @Example::example !!login ' );
$ this -> request ( ' GET / (viewName) !!login ' );
$ this -> request ( ' GET / !!login ' , function ()
{
echo ' If you see this, then you are an Admin. ' ;
});如何為用戶或Protected Rule設置有效數據?只需使用此構建的IT功能或方法即可。
$ this -> SET_RULE ( $ name );您還可以將值傳遞到Protected Rule數據中:
$ this -> SET_RULE ( $ name , $ values );這是Protected Rule的完整功能或方法:
// Check valid data for user or 'Protected Rule';
$ this -> CHECK_RULE ( $ name );
// Set new valid data for user or 'Protected Rule'.
$ this -> SET_RULE ( $ name , $ data = '' );
// Get 'Protected Rule' data.
$ this -> GET_RULE ( $ name );
// Delete valid 'Protected Rule' data.
$ this -> DESTROY_RULE ( $ name );要配置數據庫,請轉到backend/.secrets/.db 。其中包含一個配置數據庫的對象:
{ "DB_HOST" : " " , "DB_NAME" : " " , "DB_USERNAME" : " " , "DB_PASSWORD" : " " }用數據庫配置在每個密鑰值上設置。
默認情況下,存在Janggelan已驗證了目錄的URI。如果URI指的是Isset文件夾或目錄,則不會啟動Janggelan系統,因為它通過重定向到該文件夾或目錄。如果您不希望這一點發生,請打開文件backend/force.uri ,然後將舊值重寫為TRUE 。
Dali Kewara | [email protected]
Janggelan是根據MIT許可證許可的開源PHP框架。