Janggelanは、簡単なPHPフレームワークです。シンプルでありながら強力で、使用するのが楽しいです。他のフレームワークと同じように、Janggelanを理解しようとすると困難になることはありません。
Janggelanは設計され、MVCコンセプトに基づいて焦点を当てています。そのため、パフォーマンスを低下させる可能性があるため、開発に役立つ可能性のある他のツールとMVCシステムをマージしないようにしようとします。もちろん、あなたの開発を支援するためにそれを囲み続けますが、それは異なるカバーが付属しています。
詳細については、ドキュメントをお読みください。
このフレームワークを完全に完了することはできず、必要なものとは対応していなかったことを知っています。しかし、私たちは常にそれをより良く仕上げ、あなたのためにそれを予期しないようにしようとしています。あなたは私たちに貢献することができます。
いくつかの新しいツールを追加しました。
新しいより良いパフォーマンスのために、すべてのJanggelanのスクリプトを書き直しました。
サーバーの負荷を減らします。
いくつかの新しいModel方法を追加しました: where() 、 exec() 、 execute() 。
ドキュメントが追加されました。
.htaccessでキャッシュと圧縮gZipを使用しました。
PHP 7
PDO PHP拡張
Janggelanのファイルをダウンロードして、アプリケーションのディレクトリに抽出します。
共有ホスティングのためにJanggelanを公開またはインストールする場合、最も安全な方法は、 server rootの内部にJanggelanのファイルとディレクトリを配置し、 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ローカルホストサーバーを開きます:
php -S localhost:8000または、このコマンドを使用して上記を直接実行できます。
php -S localhost:8000 -t /var/www/html/your_application/public次に、ブラウザを開き、LocalHost:8000にアクセスしてください。
Janggelanでは、これをrequestsとして呼びます。 Laravelなどの他のPHPフレームワークでは、これはroutesと呼ばれます。 Janggelanのすべてのリクエストは、ファイルworksheet/requests.phpで処理されました。新しいリクエストを作成するには、そのファイルに移動します。そこには、次のようなrequestの例が表示されます。
$ this -> request ( ' GET / @Hello::world ' );上記の例には、「リクエストURI / with requestメソッドGET 。ユーザー訪問/ URIが有効な場合、リダイレクトされ、Method / Function 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
{
//
} Controller $this->LOAD_VIEW() 、 $this->GET_RULE()などのいくつかのビルトイン関数を使用する必要がない場合、 frameworkparentsControllerを拡張することを避けることができます。
Model Sは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メソッド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は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 ' ); publicまたはpublic_htmlまたはwwwディレクトリ内のあらゆる場所にworksheet/viewsの外にViewを配置したい場合は、 / :
$ 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 ' ));次に、[file example.php Viewで、変数を呼び出すだけです。
<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 、ログインシステムと同様に、 page 、 View 、またはUriを保護するためのJanggelanのシステムです。 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に有効なデータを設定する方法は?この構築された関数またはメソッドを使用してください。
$ 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に書き直します。
ダリ・ケワラ| [email protected]
Janggelanは、MITライセンスに基づいてライセンスされているオープンソースのPHPフレームワークです。