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框架。